1

私は、このエラーに関するすべてを読み、すべてを試したと思います。ここに私のモデルがあります:

主要:

public class Trip
{
    public int TripId { get; set; }
    public string Name { get; set; }
    public string ShortDescription { get; set; }
    public string Country { get; set; }
    public float BasicPrice { get; set; }
    public virtual ICollection<ApartmentType> ApartmentType { get; set; }
    public virtual ICollection<TransportMethod> TransportMethod { get; set; }
    public virtual ICollection<FeedingType> FeedingType { get; set; }
}

アパートタイプ:

public class TransportMethod
{
    public int TransportMethodId { get; set; }
    public int TripId { get; set; }
    public string Name { get; set; }
    public float Price { get; set; }
}

給餌タイプ:

public class FeedingType
{
    public int FeedingTypeId { get; set; }
    public int TripId { get; set; }
    public string Description { get; set; }
    public float Price { get; set; }
}

輸送タイプ:

public class TransportMethod
{
    public int TransportMethodId { get; set; }
    public int TripId { get; set; }
    public string Name { get; set; }
    public float Price { get; set; }
}

Trip エンティティをシリアル化すると、循環依存エラーが発生します。私が試したこと:

  1. DbContext で遅延読み込みを無効にします。
  2. json.SerializerSettings.PreserveReferencesHandling=Newtonsoft.Json.PreserveReferencesHandling.All; を追加します。GLOBAL.ASAXへ

  3. すべての子エンティティの TripId にデコレータ [IgnoreDataMember] を追加します。

  4. このエンティティを、ICollection メンバーを含まない ViewModel にマップします。- これは問題なく機能しましたが、ある時点で、これらのリストをクライアントに取得したいと考えています。

何が起こっているのか本当にわかりません。私は何が欠けていますか?私は本当に循環依存を見つけることができません。

4

1 に答える 1

1

[JsonIgnore]属性をTripId子エンティティに追加しようとしましたか?

http://james.newtonking.com/projects/json/help/html/T_Newtonsoft_Json_JsonIgnoreAttribute.htm

または設定

json.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

于 2012-12-06T21:27:18.683 に答える