2

私のモデルの内部には、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;
        }
    }

}
4

1 に答える 1

1

最初にコードを使用していると仮定します...dbcontextサブクラス内

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
     modelBuilder.Entity<Restaurant>().Ignore(x => x.attributes);
}
于 2012-11-23T19:52:12.473 に答える