Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove RemoveConvert (To avoid float conversion to integer) #13908

Closed
MaSchueler opened this issue Nov 7, 2018 · 3 comments
Closed

Remove RemoveConvert (To avoid float conversion to integer) #13908

MaSchueler opened this issue Nov 7, 2018 · 3 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@MaSchueler
Copy link

I ran into an issue with query generation in Entity Framework Core 2.1.

I have a query

var q = KostenSchweissen.Where(k => k.Grenze >= ewd)
  .OrderBy(k => k.Grenze)
  .FirstOrDefault();

with KostenSchweissen.Grenze being an integer, but ewd being a float.

So this looks for the first line with a "Grenze" greater or equal the value that is passed down.
This ran fine previously (EF Core 1.x, not sure about 2.0), but now it's generating the query (from SQL Server Profiler):

exec sp_executesql N'SELECT TOP(1) [k].[ID], [k].[Grenze], [k].[PreisEdelstahl], [k].[PreisNormalstahl]
FROM [KostenSchweissen] AS [k]
WHERE [k].[Grenze] >= @__ewd_0
ORDER BY [k].[Grenze]',N'@__ewd_0 smallint',@__ewd_0=17

where ewd was 17.1. So this completely ignores that ewd is a float, obviously returning wrong costs. Casting to a double or float in the query doesn't work, the only workaround that I could come up with is

    var q = KostenSchweissen.Where(k => k.Grenze * 1.0 >= ewd)
      .OrderBy(k => k.Grenze)
      .FirstOrDefault();

which is obviously not nice since it involves DB-side calculation. The query is not performance critical in my case, but I'm still wondering: Is this a bug, or considered a feature? If so, why? Isn't this at least a breaking change that should have been announced somewhere? Or am I just to blind to find it?

I have tried to find any hint in the EF documentation - release notes, breaking changes, forums, Stackoverflow... but couldn't find anything.

I would be thankful for any hint as to relevant documentation, best practices or whatever else could be helpful for this problem. And if this is the wrong format for asking a question like this, please forgive me.

Further technical details

EF Core version: 2.1.2
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 Pro, 1803
IDE: Visual Studio 2017 15.8.9

@ajcvickers ajcvickers changed the title float converted to integer Remove RemoveConvert (To avoid float conversion to integer) Nov 7, 2018
@ajcvickers ajcvickers added this to the 3.0.0 milestone Nov 7, 2018
@MaSchueler
Copy link
Author

Thanks for accepting this as a bug. However, 3.0.0 sounds like a long time away. Any suggestions what I can do in the meantime? Do I manually have to look for all queries where this might happen? And am I the only one who compares floats to ints?

@JonPSmith
Copy link

Hi @MaSchueler,

I have a problem in the same area that you have (see #14604). Seems like the team isn't going to fix this before version 3 and I wanted to suggest a workaround that I am going to use, i.e. DbFunctions.

I have used DbFunctions before and its a great way to replace part of a query with your own SQL - see this section of one of my articles where I use a DbFunction.

I hope that helps.

@smitpatel
Copy link
Member

This has been fixed.

@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 6, 2019
@smitpatel smitpatel modified the milestones: 3.0.0, 3.0.0-preview6 Jun 6, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0-preview6, 3.0.0 Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

No branches or pull requests

4 participants