1

I know this can be accomplished using the Fluent API on a single property, but I want to have this automatically happen for everywhere I use a .NET DateTime in my model. Here's an example of doing a single property:

modelBuilder.Entity<T>() .Property(f => f.MyDateTimeProperty) .HasColumnType("datetime2");

But instead of only on this one property I want it to happen everywhere automatically. There is a fix for this in Model First by editing the T4 generation template so I know it can be done there but I need the same thing in Code First.

1 Answer 1

5

You want to use a Custom Code First Convention.

There's an example of exactly what you are trying to do here: http://msdn.microsoft.com/en-us/data/jj819164.aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.