6

Map Class

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");

    }
}

I am getting the following error

Invalid index 6 for this SqlParameterCollection with Count= 6

Please help

connectedsoftware
  • 6,987
  • 3
  • 28
  • 43
Manoj Sethi
  • 1,898
  • 8
  • 26
  • 56

1 Answers1

13

Client Id is mapped twice, once in your cAdministratorsKey mapping and again in your Cliente mapping.

Remove the Cliente mapping and change the cAdministratorsKey mapping to include a reference to the Cliente property as shown below:

  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

This should remove the duplication and fix your issue.

connectedsoftware
  • 6,987
  • 3
  • 28
  • 43
  • This also occurs when you map a HasOne entry if you declare the ForeignKey - make sure your foreign key field isn't declared as a property if you do this. – bschipp Jan 30 '15 at 00:15
  • This also happens when you're modifying more than one object type inside the same scope. – Yuri Cardoso Feb 05 '20 at 03:21