开发者

NHibernate 3.x: Same table, three mappings, each result three times

I've three entity types: A, B and C.

These are mapped to the same database table.

B and C inherit A.

There're three records in the database table which is mapped by A, B and C.

Whenever I remain B and C mapped in the confi开发者_StackOverflowguration file, I get each entity three times.

I've tried to remove mappings for B and C, and then, I get the whole number of entities: three.

Finally, I've profiled SQL Server and the query started from the application is translated into three SQL SELECT commands.

How can I avoid this? Or I want to know if it's possible to map N classes to the same table without meaning that trying to get an entity would end in retrieving it as many times as target table is mapped.

Thank you in advance.


You need to map the class hierarchy using an inheritance mapping strategy, not by mapping each concrete class individually. Since you already store all three types in one table you should use table-per-class mapping. See this and this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜