私は、このエラーに関するすべてを読み、すべてを試したと思います。ここに私のモデルがあります:
主要:
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 エンティティをシリアル化すると、循環依存エラーが発生します。私が試したこと:
- DbContext で遅延読み込みを無効にします。
json.SerializerSettings.PreserveReferencesHandling=Newtonsoft.Json.PreserveReferencesHandling.All; を追加します。GLOBAL.ASAXへ
すべての子エンティティの TripId にデコレータ [IgnoreDataMember] を追加します。
- このエンティティを、ICollection メンバーを含まない ViewModel にマップします。- これは問題なく機能しましたが、ある時点で、これらのリストをクライアントに取得したいと考えています。
何が起こっているのか本当にわかりません。私は何が欠けていますか?私は本当に循環依存を見つけることができません。