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

Query: Translating Date using ".Contains" #7548

Closed
ole1986 opened this issue Feb 3, 2017 · 1 comment
Closed

Query: Translating Date using ".Contains" #7548

ole1986 opened this issue Feb 3, 2017 · 1 comment
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@ole1986
Copy link

ole1986 commented Feb 3, 2017

Using an IEnumarable of DateTime.Date will not properly translated:

Example:

ctx.User.Where(p => dates.Contains(p.Created.Date))

Will be translated without "Where" condition

SELECT [p].[ID], [p].[Created], [p].[UserName]
FROM [User] AS [p]

Workaround

A possible workaround (but of course not the best) is the following:

var dateStr = "'" + String.Join("','", dates.Select(p => p.ToString("yyyy-MM-dd"))) + "'";
ctx.User..FromSql("SELECT * FROM User WHERE Cast(Created as date) IN ("+dateStr+")");

Further technical details

EF Core version: 1.1.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2015

@maumar
Copy link
Contributor

maumar commented Feb 3, 2017

Still repros in current bits. Problem is in SqlTranslatingExpressionVisitor -> VisitSubquery:

var aliasExpression = VisitMember(memberItem) as AliasExpression;

when trying to create InExpression we expect operand to be an AliasExpression and what we get instead is "CONVERT"("Date, p.Created")

@rowanmiller rowanmiller added this to the 2.0.0 milestone Feb 10, 2017
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 14, 2017
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 14, 2017
@maumar maumar closed this as completed in 4514e68 Feb 14, 2017
@maumar maumar added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Feb 14, 2017
@ajcvickers ajcvickers changed the title Query: Translating Date using ".Contains" / EF 1.1.0 Query: Translating Date using ".Contains" May 9, 2017
@divega divega added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels May 10, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Oct 15, 2022
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. type-bug
Projects
None yet
Development

No branches or pull requests

5 participants