Reputation: 744
I would like a DateTime-property in my model, backed by an MSSQL2008-type that can hold at least 3 milliseconds precision. And I want to do it model-first, i.e. being able to click "Generate Database from Model..." in the VS2010 designer and get the right result without further tweaking (I know there are numerous workarounds).
My own research: I've seen some other threads on the topic of datetime2 issues, but there the problem seems to be the opposite, getting datetime2 when they want datetime. Solutions are written that suggests ProviderManifestToken="2005" in EDMX gives datetime, while ProviderManifestToken="2008" gives datetime2 behaviour.
I want datetime2 and I already have ProviderManifestToken="2008", but still only get datetime. There is an MSDN-thread that's suggesting a manually modifed T4-template. But is tweaking the T4 (or the EDMX-file in a text editor) the only ways of accomplishing datetime2 behaviour in Model First? That's not a nice way of adding precision datetime properties to your EF model...
Update: I have submitted this issue to Microsoft Connect, you can find it here. Vote for it if you want to give it a boost...
Upvotes: 5
Views: 2914
Reputation: 364369
Default SQL generation will always use DATETIME
. If you want to use DATETIME2
instead you can simply try to generate SQL script from your model and replace DATETIME
with DATETIME2
when you need it (it should work). If you want the better control over the generation you really must modify template and you must also manually modify EDMX => structural based annotations. Here is similar answer using DATE
instead of DATETIME
.
Upvotes: 3