如何使用 Fluent NHibernate 映射浮点数集合?
我有一个类,其中包含我试图在 FNH 中映射的浮点集合 (IList):
class WeeklyHours {
public virtual Person Employee { get; set; }
public virtual WeekOfYear Week { get; set; }
public virtual IList<float> DailyHours { get; set; }
}
DailyHours
成员初始化为 7 个元素的固定长度,一个元素代表相应的每一天星期。
如何在 FNH 中映射 DailyHours
?我想将所有内容保留在 "WeeklyHours"
表中,而不是创建 "Hours"
表和一对多关系。
我不能使用套装或包,因为订单很重要(一周中的某一天)。
有什么想法吗?谢谢。
I have a class that contains a collection (IList) of floats that I'm trying to map in FNH:
class WeeklyHours {
public virtual Person Employee { get; set; }
public virtual WeekOfYear Week { get; set; }
public virtual IList<float> DailyHours { get; set; }
}
The DailyHours
member is initialized to a fixed length of 7 elements, one for each day of the corresponding week.
How do I map DailyHours
in FNH? I would like to keep everything in the "WeeklyHours"
table rather than create an "Hours"
table and a one-to-many relationship.
I can't use a set or bag because order is important (day of the week).
Any ideas? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么是列表而不是数组?
这将在 WeeklyHours 表的列中创建数组的二进制表示。
编辑:另一个选项是 CustomUserType 将数组序列化/反序列化到列。如果需要,我可以发布映射
why list and not array?
this would create a binary represantation of the array in a column of the WeeklyHours-table.
Edit: another option would be a CustomUserType to serialize/deserialize the array to the column. I can post a mapping if wanted
如果您使用 Fluent NHibernate 自动映射,这应该可以正常工作,不需要程序员的任何额外帮助。
If you are using Fluent NHibernate automapping, this should just work, with no need for any additional help from the programmer.