Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体框架中编译前的DbMigration和DbModelBuilder行为_C#_Asp.net_Sql Server_Entity Framework - Fatal编程技术网

C# 实体框架中编译前的DbMigration和DbModelBuilder行为

C# 实体框架中编译前的DbMigration和DbModelBuilder行为,c#,asp.net,sql-server,entity-framework,C#,Asp.net,Sql Server,Entity Framework,我有这样一个属性: [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] public class IsUnicodeAttribute : Attribute { public bool IsUnicode { set; get; } public IsUnicodeAttribute(bool isUnicode) { this.IsUnicode = isUnicode

我有这样一个属性:

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class IsUnicodeAttribute : Attribute
{
    public bool IsUnicode { set; get; }

    public IsUnicodeAttribute(bool isUnicode)
    {
        this.IsUnicode = isUnicode;
    }
}
我在DbModelBuilder上读到:

modelBuilder.Properties<String>()
            .Having(p => p.GetCustomAttributes(false).OfType<IsUnicodeAttribute>().FirstOrDefault())
            .Configure((config, attr) => config.IsUnicode(attr.IsUnicode));
虽然还没有数据库,但我启用了迁移并添加了第一次迁移。但是,我注意到,在创建的迁移文件中,没有显示那些用属性标记为Unicode的列

是因为我在配置中出错,还是因为在运行时不知道属性的IsUnicode属性的值,还是Unicode是默认值


我使用的是EF 6.1.1。

我刚在数据库创建后检查了它,发现实际上NVARCHAR是我在类模型中声明的所有字符串属性的数据类型,而不需要在它们上面指定IsUnicode

这看起来至少是SQL Server提供程序的默认设置

编辑:我使用modelBuilder.Entity.Propertya=>a.Message.isunicodelse,创建的迁移文件实际指定了这一点。结果表明,默认情况下字符串是Unicode的,因此无需在迁移文件中指定该字符串,并且默认情况下它们看起来是NVARCHAR;不是固定大小的