DateTime mapping and precision in the first approach of the Entity Framework model

I would like to use the DateTime property in my model, supported by the MSSQL2008 type, which can contain at least 3 milliseconds. And I want to do this model-first , i.e. To be able to click "Generate Database from Model ..." in the VS2010 designer and get the correct result without additional configuration (I know that there are many workarounds).


My own research: I saw some other topics on the topic of datetime2 problems, but the problem is that the problem seems to be the opposite, getting datetime2 when they want datetime2. The solutions are written, which assumes that ProviderManifestToken = "2005" in EDMX gives the date and time, and ProviderManifestToken = "2008" gives the behavior of datetime2.

I want datetime2, and I already have ProviderManifestToken = "2008", but still get only datetime. There is an MSDN stream that offers a manually modified T4 template . But does T4 (or an EDMX file in a text editor) configure the only ways to execute datetime2 behavior in the First model? This is not a good way to add datetime precision properties to your EF model ...

Update: I sent this question to Microsoft Connect, you can find it here . Vote for him if you want to give him an impulse ...

+4
source share
1 answer

By default, SQL generation will always use DATETIME . If you want to use DATETIME2 , instead you can just try to generate an SQL script from your model and replace DATETIME with DATETIME2 when you need it (it should work). If you need better generation control, you really have to change the template, and you also have to manually change the EDMX => structure based annotations. Here's a similar answer using DATE instead of DATETIME .

+3
source

Source: https://habr.com/ru/post/1381139/


All Articles