FluentNHibernate 复合主键报错
2016-03-02 09:10
405 查看
最近学习fluentnhibernate遇到一些问题贴出来与大家共享
联合主键处理插入数据异常,废话不多说了直接上代码
字段: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);
}
}
{
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;
}
}
联合主键处理插入数据异常,废话不多说了直接上代码
数据表
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;
}
}
相关文章推荐
- c#使用FluentNHibernate,多数据库连接,一个程序,连接多个数据库
- Fluent NHibernate关于一对多时,自动创建外键的问题,
- Fluent NHibernate联合主键的使用
- NHibernate+FluentNHibernate+MySql 运行报错问题
- FluentNHibernate+NHibernate4.1+Oracle12c+VS2013 数据连接配置说明
- java swing setUndecorated(true) 无效
- 用UIActivityViewController做共享
- iOS个人整理19-UITableViewController和UITableView的编辑
- NGUI怎么进行优化?
- IOS中UIAlertView(警告框)常用方法总结
- crontab-gui
- 关于制作渐变的UIScollView渐变以及scrollView的约束问题
- codeforces 632D. Longest Subsequence 筛法
- question_003-JAVA之Context???
- question_006-JAVA之获取中文字母的首地址???
- 多种方式解决EasyUI—DataGrid中DateTime的格式化问题
- UIL加载图片的时候注意
- UINavigationBar和UINavigationItem的基本分析使用
- cf#ecr9-D - Longest Subsequence
- datagrid 后台传到页面的数据不显示