刚注册。第一个问题:) 如果我在我的域模型实体国家有名称属性和国家列表属性。此外,该州有名称,地产名单,此外,广州有市镇,最后是城市实体。创建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这样的父对象作为字符串。
希望,我很清楚:)