(流畅)NHibernate:将完整的表映射到一个对象
我有以下数据库表:
Settings
Key | Value
---------------|-------------------
SomeSetting | Foo
AnotherSetting | Bar
... | ...
并希望将其映射到以下对象:
public class Settings
{
public virtual string SomeSetting { get; set; }
public virtual string AnotherSetting { get; set; }
}
如何使用(流畅的)NHibernate 完成此操作?
I have the following database table:
Settings
Key | Value
---------------|-------------------
SomeSetting | Foo
AnotherSetting | Bar
... | ...
And want to map this to the following object:
public class Settings
{
public virtual string SomeSetting { get; set; }
public virtual string AnotherSetting { get; set; }
}
How could I accomplish this using (Fluent) NHibernate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会将键/值对映射到私有 IDictionary 并通过访问字典来公开属性。请参阅 Ayende 在地图上的博客条目了解如何创建字典。像这样的东西:
I would map the key/value pairs to a private IDictionary and expose the properties by accessing the dictionary. See Ayende's blog entry on map for creating the dictionary. Something like:
替代方案是有两列:Key,Value
将它们映射到数据库中的列,现在编写一个带有属性的存储库类,负责在键上查询数据库并获取值。您的存储库模型可能类似于您当前的对象模型。
你怎么认为?
Well an alternate would be to have two columns: Key,Value
map them into a column in the database and now write a repository class with properties will be responsible for querying the database on the key and getting the value. your repository model might resemble your current object model.
what do you think?