FluentNhibernate IDictionary
我有一个 IDictionary
属性的映射,这就是映射:
HasMany<StocksLocation>(mq => mq.StocksLocation)
.KeyColumn("IDProduct")
.AsEntityMap("IDLocation")
.Element("Quantity", qt => qt.Type<decimal>());
现在我从 decimal
更改为值对象:Quantity
。
Quantity
有两个属性,十进制 Value
和 Unit
Unit(其中 Unit
是一个枚举)。
我现在必须映射 IDictionary
,我该如何实现这一点?
提前致谢
I had a mapping for a IDictionary<StocksLocation,decimal>
property, this was the mapping:
HasMany<StocksLocation>(mq => mq.StocksLocation)
.KeyColumn("IDProduct")
.AsEntityMap("IDLocation")
.Element("Quantity", qt => qt.Type<decimal>());
Now i changed from decimal
to a Value Object: Quantity
.
Quantity
has two properties, decimal Value
and Unit
Unit (where Unit
is an enum).
I now have to map IDictionary<StocksLocation,Quantity>
, how can i achieve this?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
选项 1:将其映射为实体
我猜您的表看起来与此类似:
继续将
Quantity
映射为实体类:...然后更改
Product.StocksLocation
映射到:选项 2:将其映射为组件
因为您评论说您不想将
Quantity
映射为实体,所以让我们考虑如何将其映射为组件。Product.StocksLocation
字典的 *.hbm.xml 映射如下所示:How do we do this with FluentNHibernate?据我所知,没有一种方法可以在主干中执行此操作,因此您有几个选择:
HasManyComponent
方法。他有一个指向其项目源代码的链接,但我不知道该源代码是否包含他对 FluentNHibernate 所做的更改。ClassMap
类,并为无法使用 FluentNHibernate 映射的任何类编写 *.hbm.xml 文件。Option 1: Map it as an Entity
I'm guessing that your table looks similar to this:
Go ahead and map
Quantity
as an entity class:... and then change the
Product.StocksLocation
mapping to:Option 2: Map it as a Component
Because you commented that you'd rather not map
Quantity
as an entity, let's consider how we would map this as a component instead. The *.hbm.xml mapping for theProduct.StocksLocation
dictionary would look like this:How do we do this with FluentNHibernate? As far as I know, there isn't a method for doing this in the trunk, so you have a few options:
HasManyComponent
method. He has a link to the source code for his project, but I don't know whether that source includes the changes he made to FluentNHibernate.ClassMap
classes for others, and write a *.hbm.xml file for any classes that can't be mapped with FluentNHibernate.