-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Seeding DateTime in EF 2.1 throws exception #12211
Comments
Note for triage: I was able to reproduce this when the column is mapped to private const string DateTimeFormatConst = "{0:yyyy-MM-ddTHH:mm:ss.fffK}";
private const string DateTime2FormatConst = "{0:yyyy-MM-ddTHH:mm:ss.fffffffK}"; |
Interestingly, today I found that comparing a C# date with a database datetime directly would work: |
Ignore the DateKind in literal generation Resolves #12211
Ignore the DateKind in literal generation Resolves #12211
Ignore the DateKind in literal generation Resolves #12211
Ignore the DateKind in literal generation Resolves #12211
Ignore the DateKind in literal generation Resolves #12211
I just pulled version 2.2.0-preview2-35157 from NuGet and found this issue to still be occurring. As I said before though, it only seems to happen when using Any chance I'm just doing something wrong and there is something I can fix on my end? |
@andresdsep This fix did not make it into the preview2 release. This is why the milestone is still set to 2.0.0, and not 2.0.0-preview2. |
We found a similar issue with EF 2.1, we are getting
We could sovle it using the following approach:
Looks like there is a proble with the interpolations....Also looks lije EF have problems mapping fields defined as |
@andresdsep - I am not seeing exactly same SQL as you but in preview2 package the SQL generated is something like this, SELECT [e].[Id], [e].[TheDate]
FROM [Blogs] AS [e]
WHERE [e].[TheDate] IN ('2018-09-18T00:00:00.000-07:00')
@matipaulo - Please file a new issue with detailed repro steps. |
@smitpatel - After a lengthy interlude working on other projects, I'm finally able to verify this issue. I have run the same code as before with the new stable 2.2.0 package and found the same issue is occurring. When using |
@andresdsep - Please file a new issue with detailed repro steps. |
Created: #14095 |
Describe what is not working as expected.
I am using new way of seeding data in Entity Framework 2.1:
For example,
modelBuilder.Entity<Blog>().HasData(new Blog {BlogId = 1, CreateDate = DateTime.Now});
However, applying this to the database throws an exception. I can see that in the generated SQL the value comes as '2018-06-01T13:22:13.248-07:00' which is wrong. And since the field is obviously DateTime, I can't format it into the string the way I would want to.
If you are seeing an exception, include the full exceptions details (message and stack trace).
Stack trace:
Further technical details
EF Core version: (found in project.csproj or packages.config)
2.1.0
Database Provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 x64
IDE: (e.g. Visual Studio 2017 15.4) none (dotnet CLI). VS Community 15.7.3 is installed but not used here.
The text was updated successfully, but these errors were encountered: