NHibernate:此SqlParameterCollection的无效索引 [英] NHibernate: Invalid index for this SqlParameterCollection
问题描述
当我尝试使用NHibernate保存对象时,出现错误此SqlParameterCollection的索引无效...". 我已经阅读了很多有关该问题的答案,但它们要么与Fluent NHB有关,要么似乎不适用于我的问题(对此我可能是错的).
I'm getting an error "Invalid index... for this SqlParameterCollection" when I try to save my object with NHibernate. I've read a lot of answers about that problems but they either were about Fluent NHB or didn't seems to apply to my problem (I could be wrong about that).
这是我的hbm和我的班级:
Here are my hbm and my class :
<class name="MyWebSite.Model.ADUser" table="AD_USER">
<id name="Id" column="ID">
<generator class="native"/>
</id>
<property name="Login" column="LOGIN"/>
<property name="Hidden" column="HIDDEN"/>
<many-to-one name="Resource" column="LOGIN" property-ref="Login" cascade="none" />
</class>
[DataContract()]
public class ADUser : Entity.AbstractPersistentObject
{
[DataMember(EmitDefaultValue = false)]
public virtual string Login { get; set; }
[DataMember(EmitDefaultValue = false)]
public virtual bool Hidden { get; set; }
[DataMember(EmitDefaultValue = false)]
public virtual AbstractHumanResource Resource { get; set; }
}
AbstractPersistentObject不是我自己定义的类,我没有找到引用它的hbm文件,因此我想它没有任何映射. 它具有"ID"属性的定义(我什至没有使用其他属性).
AbstractPersistentObject is not a class I've defined myself, and I found not hbm file referencing it so I guess it's not bound to any mapping. It has the definition for the "ID" propery (I'm not even using the other ones).
[DataContract()]
public abstract class AbstractPersistentObject
{
[DataMember(EmitDefaultValue = false)]
public virtual int? Id { get; set; }
[DataMember(EmitDefaultValue = false)]
public virtual DateTime DateCreated { get; set; }
[DataMember(EmitDefaultValue = false)]
public virtual DateTime? DateUpdated { get; set; }
[DataMember(EmitDefaultValue = false)]
public virtual DateTime? DateDeleted { get; set; }
[DataMember(EmitDefaultValue = false)]
public virtual string CreatedBy { get; set; }
[DataMember(EmitDefaultValue = false)]
public virtual string UpdatedBy { get; set; }
[DataMember(EmitDefaultValue = false)]
public virtual string DeletedBy { get; set; }
public override int GetHashCode()
{
return !Id.HasValue ? base.GetHashCode() : string.Concat(this.GetType().FullName, Id.Value).GetHashCode();
}
public override bool Equals(object obj)
{
return obj == null ? false : obj.GetHashCode() == this.GetHashCode();
}
public override string ToString()
{
return this.GetType() + "#" + this.Id;
}
}
(我看不到这种继承问题)
(I don't see problems with this inheritance)
当我获得数据列表时,它可以正常工作.只有当我尝试保存它时,它会引发异常(我还没有尝试删除).
When I get a list of data, it works fine. It's only when I try to save it that it throws an exception (I didn't try deletion yet).
推荐答案
您不能将两个属性映射到同一列.如果它们不同,NHibernate应该如何决定使用哪个值?如果您确实还需要多对一关系列的纯值作为单独的属性,请使用insert="false" update="false"
映射它.
You can't map two properties to the same column. How should NHibernate decide which value to use if they differ? If you really need the plain value of the many-to-one relation column as a seperate property too then map it with insert="false" update="false"
.
这篇关于NHibernate:此SqlParameterCollection的无效索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!