使用 NHibernate 映射动态/通用属性
我有一个场景,我有一个键/值的属性包,看起来像这样:
Entry 1 : key="Load", value="2", type="int"
Entry 2 : key="DailyStatus", value="0", type="bool"
我试图弄清楚是否可以使用 nhibernate 将这些值映射到一个表,我可以稍后将其拉出到 .net 中简单类型。
我试图避免创建类来包含所有这些数据,因为它可能非常重复,并且不允许应用程序的某些部分尽可能灵活。我曾考虑过将其存储在 XML 或 JSON 中,但必须定期查询此数据。
有没有人将简单类型的字典映射到 nhibernate 中的表并将数据拉出来?我认为映射到通用字典会起作用:
IDictionary<string, IDictionary<object, Type>>
我可以手动完成它,但如果 nhibernate 有内置的方法来完成它,那就更容易了。
I have a scenario where I have a propertybag of key/values that would look something like:
Entry 1 : key="Load", value="2", type="int"
Entry 2 : key="DailyStatus", value="0", type="bool"
I am trying to figure out if it's possible with nhibernate to map these values to a single table that I can pull out at a later time into .net simple types.
I am trying to avoid creating classes to contain all of this data as it can be very repetitive and doesn't allow portions of the application to be as flexible as possible. I had considered storing it in XML or JSON, but this data has to be queried against on a pretty regular basis.
Has anyone mapped dictionaries of simple types to a table in nhibernate and pulled the data back out? I suppose mapping to a generic dictionary would work:
IDictionary<string, IDictionary<object, Type>>
I can do it by hand, but if there is a builtin way for nhibernate to accomplish it that would be easier.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您如何创建一个具有 id、key、value、type 属性的类“Triplet”,然后将其映射到一个名为您想要的任何名称的表?
How about you create a class "Triplet" with attriutes id, key, value, type and then map it to a table called whatever you want?