FluentNhibernate HasMany with component

2019-06-03 20:37发布

问题:

i have this mapping:

    HasMany<ClassA>(ot => ot.AList)
        .Table("XPTO")
        .KeyColumn("IDXPTO")
        .Component(m =>
                        {
                            m.Map(a=> a.X, "X");
                            m.Map(x=> x.Y, "Y");
                        })
         .Cascade.AllDeleteOrphan();

i get an error saying that "refers to an unmapped class ClassA", but i shouldn't need to map it. i saw other examples in the internet with similar mappings and they don't have this problem...

if i create a classMap for class A only with ID, then its works, but the data model will have 1 unecessary table for classA with only the id, because property X and Y will be mapped on the table XPTO...

回答1:

Try mapping it with specifying a type to HasMany:

    HasMany(ot => ot.AList)
    .Table("XPTO")
    .KeyColumn("IDXPTO")
    .Component(m =>
                    {
                        m.Map(a=> a.X, "X");
                        m.Map(x=> x.Y, "Y");
                    })
     .Cascade.AllDeleteOrphan();


回答2:

ok, the error of unmapped class was not due to the hasmany, but to other property i had there that refered to ClassA on a one-to-one. So i had a one-to-one relatioshi to classA and a one-to-many, the 1st one was causing the error. I solved that one to one then it worked.