具有Count = 6的此SqlParameterCollection的索引6无效

时间:2013-08-08 12:10:49

标签: c# fluent-nhibernate nhibernate-mapping fluent fluent-nhibernate-mapping

地图类

public class cAdministratorMap : ClassMap<cAdministrator>
{

    public cAdministratorMap()
    {
        Table("Administrators");

        CompositeId<cAdministratorsKey>(c => c.Key)
            .KeyProperty(x => x.Client_id, "client_id")
            .KeyProperty(x => x.Start_date, kp => kp.ColumnName("start_date").Type(DbType.Date.ToString()))
            .KeyProperty(x => x.Adm_type, kp => kp.ColumnName("adm_type").Type(DbType.AnsiString.ToString()));

        Map(x => x.Person_id, "person_id").Not.Insert().Not.Update();
        Map(x => x.end_date).Column("end_date");
        Map(x => x.description).Column("description").Length(200);

        References(x => x.Person).Column("person_id");
        References(x => x.Cliente).Column("client_id");

    }
}

我收到以下错误

  

此SqlParameterCollection的索引6无效,Count = 6

请帮忙

1 个答案:

答案 0 :(得分:13)

Client Id映射两次,一次放在cAdministratorsKey映射中,再次映射到Cliente mapping

删除Cliente映射并更改cAdministratorsKey映射以包含对Cliente属性的引用,如下所示:

  CompositeId<cAdministratorsKey>(c => c.Key)
        .KeyReference(x => x.Cliente, "client_id") // Changed to KeyReference
        .KeyProperty(x => x.Start_date, kp => kp.ColumnName("start_date").Type(DbType.Date.ToString()))
        .KeyProperty(x => x.Adm_type, kp => kp.ColumnName("adm_type").Type(DbType.AnsiString.ToString()));

  // References(x => x.Cliente).Column("client_id"); Removed as not needed

这应该删除重复并解决您的问题。