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

Entity Framework Core, computed column does not appear in WHERE clause #9979

Closed
MichaelGiger opened this issue Oct 5, 2017 · 4 comments
Closed

Comments

@MichaelGiger
Copy link

Hi

I have generated the entity model from an existing database (Scaffold-DbContext).
The table [CfgData] has following computed column [LoggerId]:
((CONVERT([bigint],[configurationID],(0))+(10000000)*CONVERT([bigint],[stationID],(0)))+(1000000000)*CONVERT([bigint],[loggerPrefix],(0)))

I had performance problem when I ran the following query:

using (var ctx = new DbContext(options))
{
    cfgDataList = await ctx.CfgData.Where(w => loggerIds.Contains((long)w.LoggerId) && w.Status).ToListAsync();
}

In the SQL Server Profiler, I've seen that the LoggerIDs are not included in the WHERE clause!

This is the SQL command that the Entity Framework is running:
SELECT [w].[configurationID], [w].[stationID], ....
FROM [dbo].[CFGData] AS [w]
WHERE [w].[status] = 1

Is this a known issue?

Further technical details

EF Core version: 1.1.2
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Win 10
IDE: Visual Studio 2017, 15.3.0

@smitpatel
Copy link
Contributor

Does it work if you remove cast to long? Contains translation was very narrow in 1.x release. It has been improved significantly in 2.0 release.

@MichaelGiger
Copy link
Author

It works fine with EF Core 2.0.0

@smitpatel
Copy link
Contributor

@MichaelGiger - Thanks for confirmation. In 1.x releases, Contains only worked if the parameter passed to it is simple member access like c.Id (no Cast or anything else otherwise). That restriction has been lifted in 2.0 now it can generate In for broader set of queries. Closing this issue as 2.0 already fixed such queries.

@smitpatel smitpatel added this to the 2.0.0 milestone Oct 6, 2017
@smitpatel
Copy link
Contributor

Duplicate of #6937

@smitpatel smitpatel marked this as a duplicate of #6937 Oct 6, 2017
@smitpatel smitpatel removed this from the 2.0.0 milestone Oct 6, 2017
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants