0
我得到一個Invalid index 22 for this SqlParameterCollection with Count=22.
異常。我知道這是一個常見問題。我也知道,幾乎每次它都與映射中的重複相關聯。但是,我是否仍然對映射知之甚少,或者是由於其他原因導致的任何幫助,我們對此表示讚賞!SqlParameterCollection異常。 NHibernate
實體的映射
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="BlackOakAccounting.DomainLayer" namespace="BlackOakAccounting.DomainLayer.Entities">
<class name="Employee" optimistic-lock="version">
<id name="ID" column="EmployeeID">
<generator class="guid.comb" />
</id>
<version name="Version" />
<!-- properties -->
<property name="EmployeeNumber" />
<property name="TradeUnionNumber" unique="true" />
<property name="Post" not-null="true" />
<property name="Department" not-null="true" />
<property name="DateOfHire" not-null="true" />
<property name="FirstName" not-null="true" />
<property name="MiddleName" not-null="true" />
<property name="LastName" not-null="true" />
<property name="DateOfBirth" not-null="true" />
<property name="SSN" not-null="true" unique="true" />
<!-- components -->
<component name="Address" class="BlackOakAccounting.DomainLayer.Components.Address">
<property name="Country" />
<property name="State" />
<property name="City" not-null="true" />
<property name="Street" not-null="true" />
<property name="Appartment" />
<property name="PostalCode" />
</component>
<component name="Passport" class="BlackOakAccounting.DomainLayer.Components.Attachment">
<property name="Description" />
<property name="ServerPath" />
</component>
<component name="EducationCertificates" class="BlackOakAccounting.DomainLayer.Components.Attachment">
<property name="Description" />
<property name="ServerPath" />
</component>
<component name="MaritalCertificates" class="BlackOakAccounting.DomainLayer.Components.Attachment">
<property name="Description" />
<property name="ServerPath" />
</component>
<component name="ChildBirthCertificates" class="BlackOakAccounting.DomainLayer.Components.Attachment">
<property name="Description" />
<property name="ServerPath" />
</component>
<component name="PersonalContact" class="BlackOakAccounting.DomainLayer.Components.Contact">
<property name="EMail" not-null="true" />
<property name="Phone" not-null="true" />
</component>
<component name="BusinessContact" class="BlackOakAccounting.DomainLayer.Components.Contact">
<property name="EMail" not-null="true" />
<property name="Phone" not-null="true" />
</component>
</class>
實體類
[Serializable]
public abstract class AbstractEntity<T> where T : AbstractEntity<T>
{
private Nullable<Int32> hashCode;
public virtual Guid ID
{
get;
private set;
}
public virtual Int32 Version
{
get;
set;
}
public override Boolean Equals(Object obj)
{
var other = obj as T;
if(other == null)
{
return false;
}
if(Equals(this.ID, Guid.Empty) && Equals(other.ID, Guid.Empty))
{
return ReferenceEquals(this, other);
}
return ID.Equals(other.ID);
}
public override Int32 GetHashCode()
{
if(this.hashCode.HasValue)
{
return this.hashCode.Value;
}
if(Equals(this.ID, Guid.Empty))
{
this.hashCode = base.GetHashCode();
return this.hashCode.Value;
}
return this.ID.GetHashCode();
}
public static bool operator ==(AbstractEntity<T> lhs, AbstractEntity<T> rhs)
{
return Equals(lhs, rhs);
}
public static bool operator !=(AbstractEntity<T> lhs, AbstractEntity<T> rhs)
{
return !Equals(lhs, rhs);
}
}
[Serializable]
public class Employee : AbstractEntity<Employee>, IAggregateRoot
{
public Employee()
{
this.Address = new Address();
this.PersonalContact = new Contact();
this.BusinessContact = new Contact();
this.EducationCertificates = new Attachment();
this.MaritalCertificates = new Attachment();
this.ChildBirthCertificates = new Attachment();
this.Passport = new Attachment();
}
// names
public virtual String FirstName { get; set; }
public virtual String MiddleName { get; set; }
public virtual String LastName { get; set; }
public virtual String SSN { get; set; }
// related to company
public virtual String EmployeeNumber { get; set; }
public virtual String TradeUnionNumber { get; set; }
public virtual String Department { get; set; }
public virtual String Post { get; set; }
public virtual DateTime DateOfHire { get; set; }
public virtual Contact BusinessContact { get; set; }
// documentation paths
public virtual Attachment EducationCertificates { get; set; }
public virtual Attachment MaritalCertificates { get; set; }
public virtual Attachment ChildBirthCertificates { get; set; }
public virtual Attachment Passport { get; set; }
// miscaleneous
public virtual DateTime DateOfBirth { get; set; }
public virtual Address Address { get; set; }
public virtual Contact PersonalContact { get; set; }
}
謝謝!