2009-02-18 107 views
1

我有以下两个表(SQL Server)的:如何为这种情况做ORM?

**IndexValues** 
IdIndexValue int (PK) 
Value varchar(2000) 
IdIndex int (FK for Table Indexes) 
IdDocument int (FK for Table Documents) 


**IndexValuesLists** 
IdIndexValueList int (PK) 
IdIndexValue int (PK with IdIndexValueList, FK for Table Indexes) 

解释了一下,从第一个表中的第二台组项目。一份文件可以在第二张桌上有各种“组别项目”。我有以下BusinessObjects类:

IndexValue { 
int Id; 
string Value; 
Document Document; 
Index Index; 
} 

IndexValueList { 
int Id; 
Document Document; 
List<List<IndexValue>> IndexesValues; 
} 

我不知道如何为最后一个属性做映射。如何在hbm.xml上做到这一点?

编辑:制作一个例子解释更多我需要什么:

IndexValues行:

IdIndexValue/Value/IdIndex/IdDocument 

1, "A", 10, 500 
2, "Circle", 11, 500 
3, "John", 12, 500 

4, "B", 10, 500 
5, "Square", 11, 500 
6, "Mary", 12, 500 

================ ======

IndexValuesLists行:

IdIndexValueList/IdIndexValue 

1, 1 
1, 2 
1, 3 
2, 4 
2, 5 
2, 6 

回答

1

List-of-lists看起来不像NHibernate会支持的那种东西。 (如果真的对你意义重大,当然你可以自由地实现对这个场景的支持。)

比这更深,你的域模型看起来有点太奇怪了。为什么你有一个索引值列表?也许你需要一个新的域实体,它有一个索引值列表,并用这个新的域实体列表替换列表列表?

+0

当然,这是一个选项。我无法改变数据库中的事情,但是如果我可以创建一个IndexValuesGroup类并执行我需要的映射,List-of-lists将不是必需的,但我认为这比列表更难,列表的东西。谢谢回复 ;) – 2009-02-18 14:22:46