nhibernate:composite-id class must override Equals()
生活随笔
收集整理的這篇文章主要介紹了
nhibernate:composite-id class must override Equals()
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
當使用NHibernate查詢表中的數據時,如果表中存在復合主鍵,如果沒有在相應的實體類中重寫Equals(),那么將會出現"Could not compile the mapping document:
TestCleanSnow.JkptGlxtUser.hbm.xml".當跟蹤出錯的內部信息的時候會發現,內部異常為"composite-id class must override Equals(): TestCleanSnow.JkptGlxtUserId"
解決辦法:
在JkptGlxtUserId.cs這個實體類中重寫Equals()方法如下:
public override bool Equals(object obj) { return base.Equals(obj); } 復制代碼
再次執行調用語句,發現還出現"Could not compile the mapping document: TestCleanSnow.JkptGlxtUser.hbm.xml".這個錯誤,但是跟蹤內部異常為:InnerException = {"composite-id class must override GetHashCode(): TestCleanSnow.JkptGlxtUserId"}
到此很明顯,在遇到復合主鍵的情況下,應該還得在JkptGlxtUserId.cs中重寫GetHashCode(),代碼如下:
public override int GetHashCode() { return base.GetHashCode(); } 復制代碼
再次運行調用程序,OK了.
TestCleanSnow.JkptGlxtUser.hbm.xml".當跟蹤出錯的內部信息的時候會發現,內部異常為"composite-id class must override Equals(): TestCleanSnow.JkptGlxtUserId"
解決辦法:
在JkptGlxtUserId.cs這個實體類中重寫Equals()方法如下:
再次執行調用語句,發現還出現"Could not compile the mapping document: TestCleanSnow.JkptGlxtUser.hbm.xml".這個錯誤,但是跟蹤內部異常為:InnerException = {"composite-id class must override GetHashCode(): TestCleanSnow.JkptGlxtUserId"}
到此很明顯,在遇到復合主鍵的情況下,應該還得在JkptGlxtUserId.cs中重寫GetHashCode(),代碼如下:
再次運行調用程序,OK了.
轉載于:https://www.cnblogs.com/zjoch/archive/2012/01/31/2333877.html
總結
以上是生活随笔為你收集整理的nhibernate:composite-id class must override Equals()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CentOS 5.x 系统下使用yum
- 下一篇: memcache的深度解析(转)