在我的模型中,我有一个名为attributes
的属性,其值取自我的数据库中的cutomized_attributes
属性attributes
在数据库中不存在其刚刚计算的值,虽然我试图做以下事情但我面临这个错误:
错误:System.Data.Entity.Edm.EdmEntityType :: EntityType' JToken'没有定义键。定义此EntityType的键
型号:
public class Restaurant
{
public int id{ get; set; }
public string name{ get; set; }
public string cutomized_attributes { get; set; }
private JObject _attributes { get; set; }
public JObject attributes
{
get
{
if (this._attributes == null)
return this._attributes = RestaurantAttributes.parseAttrString(this.cutomized_attributes);
return this._attributes;
}
set
{
this._attributes = value;
}
}
}
答案 0 :(得分:1)
假设您首先在dbcontext子类中使用代码
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Restaurant>().Ignore(x => x.attributes);
}