zoukankan      html  css  js  c++  java
  • nhibernate:compositeid 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()方法如下:


    1. public override bool Equals(object obj)
    2. {
    3. return base.Equals(obj);
    4. }
    复制代码


    再次执行调用语句,发现还出现"Could not compile the mapping document: TestCleanSnow.JkptGlxtUser.hbm.xml".这个错误,但是跟踪内部异常为:InnerException = {"composite-id class must override GetHashCode(): TestCleanSnow.JkptGlxtUserId"}
    到此很明显,在遇到复合主键的情况下,应该还得在JkptGlxtUserId.cs中重写GetHashCode(),代码如下:

    1. public override int GetHashCode()
    2. {
    3. return base.GetHashCode();
    4. }
    复制代码


    再次运行调用程序,OK了.
  • 相关阅读:
    面向对象 小游戏 打飞机
    面向对象2
    面向对象
    正则 校验邮箱
    正则 过滤敏感字
    Strobogrammatic Number
    Binary Tree Right Side View
    [?]*Closest Binary Search Tree Value II
    *Closest Binary Search Tree Value
    *Inorder Successor in BST
  • 原文地址:https://www.cnblogs.com/zjoch/p/2333877.html
Copyright © 2011-2022 走看看