Configure EF6 to use varchar as default instead of nvarchar?

ef-code-first entity-framework-6

Question

I am aware that I may set the column type for each property by adding a Data Annotation.VARCHAR however, I want to write hundreds more columns.VARCHAR in place ofNVARCHAR Is there a way to configure EF6 so that this is the default setting?

1
19
5/13/2015 7:03:20 PM

Accepted Answer

I believe you can implement something like this after researching EF conventions:

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

This is essentially a copycat of http://msdn.microsoft.com/en-us/data/jj819164#order, and it hasn't been put to the test.

As @Shimmy notes in the comments, in addition toc => c.IsUnicode(false) It seems to accomplish the same goal without a column type being hardcoded.

29
5/8/2015 11:15:34 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow