使用NHibernate出现错误"此SqlParameterCollection 的 Count=71 的索引 71 无效"

使用nhibernate做update操作时出现如下错误:

此 SqlParameterCollection 的 Count=71 的索引 71 无效。

 XML文件

<? xml version="1.0" encoding="utf-8"  ?>
< hibernate-mapping  xmlns ="urn:nhibernate-mapping-2.2" >
   < class  name ="PERSON, Sgidi.Model"  table ="PERSON" >
     < id  name ="PNUMBER"  type ="String"  unsaved-value ="null" >
       < column  name ="PNUMBER"  length ="50"  sql-type ="varchar"  not-null ="true"  unique ="true"  index ="PK_PERSON_1" />
       < generator  class ="native"   />
     </ id >
     < property  name ="roomcode"  type ="String" >
       < column  name ="room_code"  length ="10"  sql-type ="varchar"  not-null ="true" />
     </ property >
     < many-to-one  name ="dept_info"  class ="dept_info"  column ="room_code"  not-found ="ignore" />
   </ class >
</ hibernate-mapping >

 有两种解决方法

1.配置文件

<? xml version="1.0" encoding="utf-8"  ?>
< hibernate-mapping  xmlns ="urn:nhibernate-mapping-2.2" >
   < class  name ="PERSON, Sgidi.Model"  table ="PERSON" >
     < id  name ="PNUMBER"  type ="String"  unsaved-value ="null" >
       < column  name ="PNUMBER"  length ="50"  sql-type ="varchar"  not-null ="true"  unique ="true"  index ="PK_PERSON_1" />
       < generator  class ="native"   />
     </ id >
     < property  name ="roomcode"  type ="String"  insert ="false"  update ="false"   >
       < column  name ="room_code"  length ="10"  sql-type ="varchar"  not-null ="true" />
     </ property >
     < many-to-one  name ="dept_info"  class ="dept_info"  column ="room_code"  not-found ="ignore" />
   </ class >
</ hibernate-mapping >

 但这样的话以后字段roomcode不能进行修改操作

 

2.配置文件

 

<? xml version="1.0" encoding="utf-8"  ?>
< hibernate-mapping  xmlns ="urn:nhibernate-mapping-2.2" >
   < class  name ="PERSON, Sgidi.Model"  table ="PERSON" >
     < id  name ="PNUMBER"  type ="String"  unsaved-value ="null" >
       < column  name ="PNUMBER"  length ="50"  sql-type ="varchar"  not-null ="true"  unique ="true"  index ="PK_PERSON_1" />
       < generator  class ="native"   />
     </ id >
     < property  name ="roomcode"  type ="String"  insert ="false"  update ="false"   >
       < column  name ="room_code"  length ="10"  sql-type ="varchar"  not-null ="true" />
     </ property >
     < many-to-one  name ="dept_info"  class ="dept_info"  column ="room_code"  not-found ="ignore"
 insert ="false"  update ="false"
/>
   </ class >
</ hibernate-mapping >

参考资料:


 

转载于:https://www.cnblogs.com/Byrd/archive/2011/10/08/2201774.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值