Mapping Problems : Composite Key for Identity column
Posted: Tue 17 May 2011 09:18
Hello,
Am working on the mapping Composite Keys(NUMBER+ CLIENTID) for
Table , Here both these keys are primary Keys and NUMBER field is
autogenerated and set as Identity in Database. am facing a problem
for mapping these fields as composite keys.
Error : "a different object with the same identifier value was already
associated with the session"..---> this is becoz in Database this
column is already set as Identity Column ..
Please refer the below code
public cliPendingBankruptcyMap()
{
Table("cliPendingBankruptcy");
LazyLoad();
CompositeId()
.KeyReference(x => x.usrClient, "CLIENTID")
.KeyProperty(x => x.NUMBER, "NUMBER");// HOW TO SET
THIS FIELD AS IDENTITY.
Map(x => x.NAME).Column("NAME");
Map(x => x.CASENO).Column("CASENO");
Map(x => x.DATE).Column("DATE");
Map(x => x.DISTRICT).Column("DISTRICT");
Map(x => x.RELATION).Column("RELATION");
Map(x => x.JUDGE).Column("JUDGE");
}
How can we set the Identity property for NUMBER field in the above
CompositeId()?? , So what approach should we need to follow for
mapping the NUMBER field as Identity in the above code.
Your thoughts?
Am working on the mapping Composite Keys(NUMBER+ CLIENTID) for
Table , Here both these keys are primary Keys and NUMBER field is
autogenerated and set as Identity in Database. am facing a problem
for mapping these fields as composite keys.
Error : "a different object with the same identifier value was already
associated with the session"..---> this is becoz in Database this
column is already set as Identity Column ..
Please refer the below code
public cliPendingBankruptcyMap()
{
Table("cliPendingBankruptcy");
LazyLoad();
CompositeId()
.KeyReference(x => x.usrClient, "CLIENTID")
.KeyProperty(x => x.NUMBER, "NUMBER");// HOW TO SET
THIS FIELD AS IDENTITY.
Map(x => x.NAME).Column("NAME");
Map(x => x.CASENO).Column("CASENO");
Map(x => x.DATE).Column("DATE");
Map(x => x.DISTRICT).Column("DISTRICT");
Map(x => x.RELATION).Column("RELATION");
Map(x => x.JUDGE).Column("JUDGE");
}
How can we set the Identity property for NUMBER field in the above
CompositeId()?? , So what approach should we need to follow for
mapping the NUMBER field as Identity in the above code.
Your thoughts?