Using NHibernate, is there a quick way to map the foll开发者_运维技巧owing class:
public class Office
{
    public virtual Guid Id { get; set; }
    public virtual IList<DateTime> Holidays { get; set; }
}
...to the tables:
table Office { Guid Id }
table OfficeHolidays { Guid OfficeId, DateTime Holiday }
Quick? I think so. Create an OfficeHoliday class and map it as one-to-many from Office, maping the collection as a private member in Office. Then expose the Holidays property and methods to maintain it.
public class Office
{
    private IList<OfficeHoliday> _officeHolidays;
    public virtual Guid Id { get; set; }
    public IEnumerable<DateTime> Holidays
    {
        get { return _officeHolidays.Select(x => x.Holiday); }
    }
    public void AddHoliday(DateTime holiday)
    {
        // should check if it already exists first...
        var newHoliday = new OfficeHoliday(this, holiday.Date);
        _officeHolidays.Add(newHoliday);
    }
    public void RemoveHoliday(DateTime holiday)
    {
        var removeHoliday = _officeHolidays.FirstOrDefault(x => x.Holiday == holiday.Date);
        if (removeHoliday != null)
        {
            _officeHolidays.Remove(removeHoliday);
        }
    }
}
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论