-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Using Contains: Conversion failed when converting date and/or time from literal #14095
Comments
Same problem here. |
I had this problem using I fixed it using |
I am having the same issue when executing
|
Having the same issue when comparing dates, because the only resolution is changing all the DB tables datetime to datetime2 we couldn't use the framework. |
I ran into the same issue. My issue was using datetime column type in my SQL table. I guess the default for EF Core is datetime2(7) and it is also the recommendation by Microsoft for SQL datetime types. But you can specify the column type using:
Thus:
You should be able to specify if using datetime2 the actual precision here for example |
@smitpatel I'm not sure exactly what to try reproduce here, I asked Arthur and he wasn't sure either and to ask you :) |
Mainly contains with type inference is issue. Create a model which has DateTime property mapped to something other than datetime2(7) in SqlServer. |
Describe what is not working as expected.
If you are seeing an exception, include the full exceptions details (message and stack trace).
Steps to reproduce
Using conventions based mapping with EF Core, I've found that querying the database thru equality using a C# date with a database datetime directly would work:
Using Contains would not:
The first expression produces something like:
whereas the second produces:
Further technical details
EF Core version: 2.2.0 (stable)
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Win 10 x64
IDE: Visual Studio 2017 15.8.7
The text was updated successfully, but these errors were encountered: