【发布时间】:2012-07-06 18:41:21
【问题描述】:
我正在构建我的第一个小型 RavenDB 应用程序,我想知道在构建域模型时我是否正确地处理了事情。
我有一个国家列表,我想在我的模型中的多个位置使用这些国家/地区。通常在过去我会创建一个数据库表来存储国家和一个国家对象,看起来有点像这样:
public class Country{
public int Id {get;set;}
public string CountryName {get;set;}
}
当我使用 country 类时,我会在另一个对象中保存它的一个实例,例如:
public class Shop{
public int Id {get;set;}
public string Name {get;set;}
public Country InCountry {get;set;}
}
或者
public class Customer{
public int Id {get;set;}
public string Surname {get;set;}
public Country CountryOfResidence {get;set;}
}
等等等等。我认为我现在应该做的是将国家/地区的 Id 存储在 Shop 和 Customer 类中是否正确,所以它们现在看起来像这样:
public class Shop{
public int Id {get;set;}
public string Name {get;set;}
public int CountryId {get;set;}
}
public class Customer{
public int Id {get;set;}
public string Surname {get;set;}
public int CountryOfResidenceId {get;set;}
}
当我从数据库中提取这些内容时,我可以使用 Raven API 的包含功能来获取相关的国家/地区对象,尽管它位于一个单独的对象中,例如我不能这样做 myCustomer.Country.Name。
显然这是一个非常人为的例子,但我真的只是想在继续这条路线之前检查一下我没有完全错误地吠叫。
【问题讨论】:
标签: domain-driven-design ravendb