您的位置:首页 > 产品设计 > UI/UE

FluentNHibernate 复合主键报错

2016-03-02 09:10 405 查看
最近学习fluentnhibernate遇到一些问题贴出来与大家共享


联合主键处理插入数据异常,废话不多说了直接上代码

数据表

rtc_depart

字段:schoolid --学校ID 主键

            depid   --部门ID  主键

            depname  部门名称

首先Map类

public class rtc_departMap : ClassMap<rtc_depart>

    {

        public rtc_departMap() {

            Table("rtc_depart");

            CompositeId().KeyProperty(s => s.depid, "depid").KeyProperty(s=>s.schoolid, "schoolid");

            Map(s => s.depname);

        }

    }

 

然后是Model

 public class rtc_depart

    {

        public virtual string schoolid { get; set; }//学校ID---主键

        public virtual string depid { get; set; }//部门ID---主键

        public virtual string depname { get; set; }//部门名称

        public override bool Equals(object obj)

        {

            if (obj == null) return false;

            var t = obj as rtc_depart;

            if (t == null) return false;

            if (schoolid == t.schoolid && depid == t.depid)

            {

                return true;

            }

            return false;

        }

        public override int GetHashCode()

        {

            int hash = GetType().GetHashCode();

            hash = (hash * 397) ^ schoolid.GetHashCode();

            hash = (hash * 397) ^ depid.GetHashCode();

            return hash;

        }

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  FluentNHibernate