c# - NHibernate: Use one column for relationship and primary key, Invalid index for this SqlParameterCollection -


i've defined composite-id nhibernate database model. i've used 1 of columns defined in foreign key relationship too. if insert object using nhibernate, following exception:

system.indexoutofrangeexception: invalid index 7 sqlparametercollection count=7.
@ system.data.sqlclient.sqlparametercollection.rangecheck(int32 index)
@ system.data.sqlclient.sqlparametercollection.getparameter(int32 index)
@ nhibernate.type.int32type.set(idbcommand rs, object value, int32 index)
@ nhibernate.type.nullabletype.nullsafeset(idbcommand cmd, object value, int32 index)
@ nhibernate.type.nullabletype.nullsafeset(idbcommand st, object value, int32 index, isessionimplementor session)
@ nhibernate.type.componenttype.nullsafeset(idbcommand st, object value, int32 begin, isessionimplementor session)
@ nhibernate.persister.entity.abstractentitypersister.dehydrate(object id, object[] fields, object rowid, boolean[] includeproperty, boolean[][] includecolumns, int32 table, idbcommand statement, isessionimplementor session, int32 index)
@ nhibernate.persister.entity.abstractentitypersister.insert(object id, object[] fields, boolean[] notnull, int32 j, sqlcommandinfo sql, object obj, isessionimplementor session)
@ nhibernate.persister.entity.abstractentitypersister.insert(object id, object[] fields, object obj, isessionimplementor session)
@ nhibernate.impl.statelesssessionimpl.insert(string entityname, object entity)
@ nhibernate.impl.statelesssessionimpl.insert(object entity)

is possible use 1 column 2 different purposes (foreign key relationship , primary key)?

c# nhibernate model

public const string str_id = "id"; public const string str_shardkey = "shardkey"; public const string str_othermodel = "othermodel";  [compositeid(-4)] [keyproperty(-3, name = str_id, column = str_id)] [keyproperty(-2, name = str_shardkey , column = str_shardkey )] [generator(-1, class = "guid.comb")] public virtual guid? id { get; set; }  [column(name = str_shardkey )] public virtual int shardkey{ get; set; }  [manytoone(0)] [column(1, name = str_othermodel )] [column(2, name = str_shardkey )] public virtual othermodel othermodel { get; set; } 

xml mapping

<composite-id>     <key-property name="id" column="id" />     <key-property name="shardkey" column="shardkey" /> </composite-id>  <many-to-one name="othermodel" >     <column name="othermodel" />     <column name="shardkey" /> </many-to-one> 


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -