根據Dylan對問題'Using The Repository Pattern, Is It Best To Save Parent and Children Objects Together Or Separately?'的回答,資料庫會保存整個集合(父母和子女)。一個人如何着手將一個聚集(父母和孩子)保存在一個存儲庫中?
這是怎麼回事,這將在實際存儲過程中編碼(如果使用它們);你會調用子庫,以及...
例如具有與城市孩子列表的父類國家:
class Country
{
List<City> cities;
...
}
和倉庫片段:
public Save(Country country)
{
...
ICityRepository cityRepository = new CityRepository();
foreach (City city in country.Cities)
{
cityRepository.Save(city);
}
...
}
或有更好的選擇嗎?
另外,如果上面的例子調用了子庫,如果有很多孩子,會有很大的性能影響?