2012-02-27 49 views
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; }   
} 

谢谢!

回答

0

我明白,我错了。所以每个

<property name="Description" /> 
<property name="ServerPath" /> 

属性对我需要指定一个唯一的列名,因为组件没有被映射直通的表和字段只得到复制!