EF Code First - Globally set varchar mapping over nvarchar

后端 未结 4 1040
广开言路
广开言路 2020-12-14 19:39

I have what should be an easy question but I have been unable to find the answer myself.

I am using EF4 CTP-5 Code First Model with hand generated POCOs. It is proc

4条回答
  •  無奈伤痛
    2020-12-14 19:59

    Before EF 4.1, you could use conventions and add the following convention to your ModelBuilder:

    using System;
    using System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive;
    using System.Data.Entity.ModelConfiguration.Conventions.Configuration;
    using System.Reflection;
    
    public class MakeAllStringsNonUnicode :
        IConfigurationConvention
    {
        public void Apply(PropertyInfo propertyInfo, 
                          Func configuration)
        {
            configuration().IsUnicode = false;
        }
    }
    

    (Taken from http://blogs.msdn.com/b/adonet/archive/2011/01/10/ef-feature-ctp5-pluggable-conventions.aspx)


    UPDATE: Pluggable conventions were dropped for the 4.1 release. Check my blog for an alternative approach)

提交回复
热议问题