剛註冊。第一個問題:) 如果我在我的域模型實體國家有名稱屬性和國家列表屬性。此外,該州有名稱,地產名單,此外,廣州有市鎮,最後是城市實體。創建DTO,有點困惑
爲了更好地exaplain:我想seriliaze與CountryDTO國家實體和我的構造器看起來像這樣:
public CountryDTO(Country x)
{
Name = x.Name;
StateList = new List<StateDTO>();
foreach (State state in x.States)
{
StateDTO stateDto = new StateDTO(state);
StateList.Add(stateDto);
}
}
但是,當我與StateDTO它看起來像這樣>
public StateDTO(State x)
{
Name = x.Name;
CountryDTO Country = new CountryDTO(x.Country);
CantonList = new List<CantonDTO>();
foreach (Canton c in x.Cantons)
{
CantonDTO cantonDto = new CantonDTO(c);
CantonList.Add(cantonDto);
}
}
不斷深入
由於我的StateDTO應該知道他的國家父對象,我有這條線 CountryDTO Country = new CountryDTO(x.Country);這是問題,(可能是遞歸引用),這會發生在州與他們的狀態對象作爲父,等等。 那麼如何加載這個父實體,並避免這個錯誤。 我需要引用像Country.Name no CountryName這樣的父對象作爲字符串。
希望,我很清楚:)