Mus*_*o31 0 c# entity-framework ef-code-first
我收到错误,The property 'Rank' is not a declared property on type 'MasterUser'. Verify that the property has not been explicitly excluded from the model by using the Ignore method or NotMappedAttribute data annotation. Make sure that it is a valid primitive property.我检查了我的模型类,它就在那里.
public class MasterUser
{
//many other properties...
public virtual char Rank { get; set; }
//more properties below
}
Run Code Online (Sandbox Code Playgroud)
我还检查了我的数据库上下文,它也在那里并完美映射.
public class BBDataContext : DbContext
{
public DbSet<MasterUser> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
#region MUSR_USRID mapping
//Mapped properties above....
modelBuilder.Entity<MasterUser>()
.Property(usr => usr.Rank).HasColumnName("MUSR_RANK");
//More mapped properties..
modelBuilder.Entity<MasterUser>().ToTable("dbo.MUSR_FIL");
#endregion
base.OnModelCreating(modelBuilder);
}
}
Run Code Online (Sandbox Code Playgroud)
在表中,MUSR_RANK可以使用char数据类型为空.
我怎样才能解决这个问题?数据库对此有影响吗?我目前正在使用SQL Server 2000.
谢谢您的帮助.
所以,你必须使用string的,而不是一个char,我觉得
并添加一些数据 OnModelCreating
modelBuilder.Entity<MasterUser>()
.Property(usr => usr.Rank).HasColumnName("MUSR_RANK")
.HasMaxLength(1)
.IsFixedLength()
.IsUnicode(false);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4445 次 |
| 最近记录: |