FluentNhibernate HasMany with component

2019-06-03 20:09发布

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...

2条回答
乱世女痞
2楼-- · 2019-06-03 20:35

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.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-06-03 20:39

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();
查看更多
登录 后发表回答