1
votes

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.

2

2 Answers

0
votes

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

0
votes

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