How to map One-To-Many in NHibernate using Set/List/Bag (by code)

959 Views Asked by At

Two simple classes:

public class Order
{
     public virtual IList<OrderLine> Lines { get; set; }
}

public class OrderLine
{
   ....
}

I try to do mapping by code using:

public class OrderLineMapping : ClassMapping<OrderLine>
{
    OrderLineMapping ()
    {
         Id(...)
         Property(x=>...)
    }
}

public class OrderMapping : ClassMapping<Order>
{
    OrderMapping ()
    {
         Id(...)
         Property(x=>...)

         // Set, Bag or List
         Set(x=> x.OrderLines, m ={       
});

    }
}

When schema is being generated, it says:

NHibernate.MappingException: Could not determine the type for OrderLine, for columns: NHibernate.Mapping.Column(id) (...)

What am I missing to be able to get the One-To-Many relation working? If I skip mapping the OrderLines property in the OrderMapping, and go straight to saving an OrderLine, I have no problem.

Also: can anyone point me in a direction where I can find good documentation regarding mapping by code?

Thank you!

1

There are 1 best solutions below

0
On

Found out the missing part - or at least one that is working:

Set(x => x.Lines, m => { }, r => r.OneToMany());