fluent nhibernate component one-to-many

前端 未结 3 964
执笔经年
执笔经年 2020-12-22 12:28

I have couple of classes and want to map them correctly to database:

public class A
{
    public virtual Guid Id { get; private set; }
    public virtual Com         


        
相关标签:
3条回答
  • 2020-12-22 13:25

    Ok, I've resolved my problem - I can use Id of my "parent" class. So the component mapping will become:

    public class AMap : ClassMap<A> 
    {
        public A() {
            Id(x => x.Id);
            Component(x => x.Component,
                      c => c.HasMany(x => x.Elements).Cascade.All().Column("Id"));
        }
    }
    

    So obvious as I look at it now ... but It took me an hour.

    0 讨论(0)
  • 2020-12-22 13:25

    If you have a one-to-many association direct to a collection of components (ie. without the ComponentClass wrapper as per the question) then you can map it directly:

    HasMany(x => x.Elements)
        .AsSet()
        .Table("ElementTable")
        .KeyColumn("KeyColumn")
        .Cascade.All()
        .Component(x =>
        {
            x.Map(c => c.Id);
            x.Map(c => c.Time);
        })
        .LazyLoad();
    
    0 讨论(0)
  • 2020-12-22 13:29

    I believe Components are supposed to be in the same table , as clearly stated in Ayende's blog post, as they serve only to make the data better represented as an object model. Be sure to read through his blog, it's probably one of the best nHibernate resources out there.

    0 讨论(0)
提交回复
热议问题