2009-02-18 57 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