1
votes

I have just started working on a project using Fluent NHibernate.

What is the correct way to map the following classes using Fluent NHibernate?

public class DurationUnit
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
}

public class Duration
{
    public virtual int Value { get; set; }
    public virtual DurationUnit Unit { get; set; }
    public virtual int DurationInMinutes { get{ throw new NotImplementedException(); } }
}

public class Event
{
    public virtual int Id { get; set; }
    public virtual String Name { get; set; }
    public virtual Duration MaxDuration { get; set; }
    public virtual Duration MinDuration { get; set; }
}

My inital approach was to declare a ClassMap for DurationUnit and Event, with Duration as a component of Event. When trying this I received an exception:

NHibernate.MappingException: Could not determine type for: Entities.DurationUnit

1

1 Answers

2
votes

if your mapping looks like this

public EventMap()
{
    Component(x => x.MaxDuration, c =>
    {
        c.Map(x => x.Value, "MaxDurationValue");
        c.Reference(x => x.Unit, "MaxDurationUnitId");
    });
}

then make sure class DurationUnitMap is public and is added to the configuration