Dar*_*der 37 c# sql-server indexing performance entity-framework
我正在使用Entity Framework 6.1代码优先,我的域模型如下.
class Item
{
[Index]
public string CreatedBy { set; get; }
}
Run Code Online (Sandbox Code Playgroud)
当我使用update-database进行迁移时,我收到以下错误.但是,据我所研究,[Index]应该作为注释string.
表'dbo.Items'中的列'CreatedBy'的类型无效,无法用作索引中的键列.
Tal*_*sif 86
通常,当您使用VARCHAR(Max)尝试使用时会出现此错误:
[Column(TypeName = "VARCHAR")]
[StringLength(n)]
[Index]
public string CreatedBy { set; get; }
Run Code Online (Sandbox Code Playgroud)
其中n介于1和450之间.
如果您使用EntityTypeConfiguration aka映射:
public class MyPocoEntitiyTypeConfig<T> : EntityTypeConfiguration<T> where T:class
{
}
public class MyPocoEnt
{
public virtual string MyProp { get; set; }
}
public class MyPocoEntMapping : MyPocoEntitiyTypeConfig<MyPocoEnt>
{
public MyPocoEntMapping()
{
Property(x => x.MyProp).HasMaxLength(300);
Property(x => x.MyProp).HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("MyProp") { IsUnique = true }));
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13308 次 |
| 最近记录: |