FluentNhibernate HasMany with component

烂漫一生 提交于 2019-12-23 02:45:01

问题


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.



来源:https://stackoverflow.com/questions/2117156/fluentnhibernate-hasmany-with-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!