使用 Fluent NHibernate 解析将两列映射到一个字段
我有一个对象(Limit),其中包含两个类型为 ParsedValue 的字段(Low、High)。 ParsedValue 具有:
constructor (double, string);
method string ToString();
每个 ParsedValue 都有它的值:double 和单位:string 并表示带有单位的某些测量值。
我想要一个包含字段的表:
low:double
high:double
unit:string
因此,当选择 Limit 对象时,我需要用 new ParsedValue(low, unit) 填充 Low 字段,用 new ParsedValue(high, unit) 填充 High 字段。将 Limit 对象插入数据库时,应插入 low=Low.Value、high=High.Value、unit=Low.Unit
如何使用 Fluent NHibernate 做到这一点?
I have an object (Limit) that contains two fields (Low, High) with type ParsedValue.
ParsedValue has:
constructor (double, string);
method string ToString();
Each ParsedValue has it's value:double and unit:string and represents some measurement with a unit.
I want to have a table with fields:
low:double
high:double
unit:string
So when selecting Limit object I need to fill Low field with new ParsedValue(low, unit) and High field with new ParsedValue(high, unit). When inserting Limit object to the database, it should insert low=Low.Value, high=High.Value, unit=Low.Unit
How can I do that using Fluent NHibernate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
扩展布鲁克的评论:
假设以下类
映射
ImmutableUserType 是我对不可变类型的 IUserType 的实现。如果需要的话我可以发布代码。
这会将限额保存在与其持有者相同的表中
extending Brook's Comment:
assuming following classes
the mapping
ImmutableUserType is my implementation of IUserType for immutable types. I can post the code if needed.
this would save the Limit in the same Table as the holder of it