NHibernate的域对象跨越多个表 [英] NHibernate Domain Object Spans Multiple Tables

查看:110
本文介绍了NHibernate的域对象跨越多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public class SpansMultipleTables 
{
public int CommonID​​ {get; set;}

public string Table1Value {get; set;}

public int Table2Value {get; set;}

public float Table3Value {get;设置;}
}




  • CommonID​​属性映射到
  • Table1Value属性映射到表Table1的Value列中
  • Table2Value属性映射到TableTable2中的Value列
  • Table3Value属性映射到表Table3中的Value列



使用FluentNHibernate,我怎样才能为这个对象设置一个真的没有中央表的地图?


Assume I have this domain object...

public class SpansMultipleTables
{
     public int CommonID {get; set;}

     public string Table1Value {get; set;}

     public int Table2Value {get; set;}

     public float Table3Value {get; set;}
}

  • The CommonID property maps to the "ID" column on all tables.
  • The Table1Value property maps to the "Value" column in the table "Table1"
  • The Table2Value property maps to the "Value" column in the table "Table2"
  • The Table3Value property maps to the "Value" column in the table "Table3"

Using FluentNHibernate, how can I set up a map for this object that really doesn't have a central table as it's home?

解决方案

I'm not an expert, but I'm not sure if NHibernate can easily handle a mapping like this. If you are able to modify the schema, you might be able to define a "master" table, which just has the CommonID as the primary key. The class for the master table can then map the other tables as properties by their relationship to the master table. Another option might be to designate one of the tables as the master, and have the others mapped as properties on the master class. In any case, it would probably be a good idea to create some FK relationships between these tables to guarantee that the combined "entity" cannot have its parts removed separately.

这篇关于NHibernate的域对象跨越多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆