如何在不属于数据库的模型中设置属性

时间:2012-11-23 17:33:12

标签: asp.net-mvc model-view-controller asp.net-mvc-4

在我的模型中,我有一个名为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;
        }
    }

}

1 个答案:

答案 0 :(得分:1)

假设您首先在dbcontext子类中使用代码

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
     modelBuilder.Entity<Restaurant>().Ignore(x => x.attributes);
}