2009-06-18 75 views
0

試圖環繞NHibernate的我的頭,curiuos如何之情況會進行處理:我如何將這個映射到nHibernate中?

Post (postID, title, content, dateCreated) 
Category (categoryID, name, postCount) 

post_to_categories (postID, categoryID) 

如果我創建一個Post,它應該插入Post,插入post_to_categories和更新CategorypostCount

我計劃也使用iRepository模式。

這將如何完成與nHibernate? (映射文件的例子?)

回答

0

這個「硬」部分似乎是更新類別表中的帖子數......但爲什麼更新它?你可以這樣定義的值(映射文件裏,爲Category):

<property name="PostCount" formula="select count(*) from Posts p where p.Id = Id" /> 

如果您的帖子對類是多對多的,它應該是可以擴展上面,以支持這一點。

相關問題