开发者

How to map collection of floats using Fluent NHibernate?

开发者 https://www.devze.com 2023-04-10 07:23 出处:网络
I have a class that contains a collection (IList) of floats that I\'m trying to map in FNH: class WeeklyHours {

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> Dail开发者_如何学GoyHours { 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.


why list and not array?

public virtual float[] DailyHours { get; private set; }

public WeeklyHours()
{
     DailyHours = new float[7];
}


Map(x => x.DailyHours);

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


If you are using Fluent NHibernate automapping, this should just work, with no need for any additional help from the programmer.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号