0

LINQ-to-SQLを使用していますが、シリアライゼーションモードを単方向に設定しています。DataContractSerializerでシリアル化されていない接続エンティティ

私は、1対多の関係を持つCountryCityの2つのエンティティクラスを持っています。

DataContractSerializer serializer = 
    new DataContractSerializer(typeof(IList<Country>), new[] { 
    typeof(EntitySet<City>) // I have also tried with typeof(City) 
    }); 
string xml; 
using (Db db = new Db()) { 
    IList<Country> countries = db.Countries.ToList(); 
    // ... some manipulation of the list here, add/remove etc ... 
    StringBuilder sb = new StringBuilder(); 
    using (XmlWriter writer = XmlWriter.Create(sb)) 
    serializer.WriteObject(writer, countries); 
    xml = sb.ToString(); 
} 

結果のXML文字列がCountryエンティティが、その中にありませんCity実体を持っています。

どうすれば解決できますか?

答えて

1

ToList()を呼び出すと問題が発生しているようです。

関連する問題