Configure EF6 to use varchar as default instead of nvarchar?

ef-code-first entity-framework-6

Question

I know I can add a Data Annotation to each property to set it's column type to VARCHAR but I have hundreds of columns I want to be VARCHAR instead of NVARCHAR is there some way to setup EF6 to make this the default?

Accepted Answer

Looking up EF conventions, I think you can do something like this:

modelBuilder.Properties<string>().Configure(c => c.HasColumnType("varchar"));

I largely ripped this off from http://msdn.microsoft.com/en-us/data/jj819164#order and haven't tested it.

[Edit:] As @Shimmy points out in the comments, there's also c => c.IsUnicode(false) which appears to do the same thing without hardcoding a column type.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why