NHibernate问题求大神解决!!!
这是我定义的实体类
对应的数据库表
映射文件
数据访问层写的是插入语句
错误:
捕捉到 nhibernate.exceptions.genericadoexception
hresult=-2146232832
message=could not insert: [dayou.yun.entity.entities.subscriptionentity][sql: insert into subscription (membershipid, subscription_number, productid, createtime, audittime, adminid, remarks, state) values (?, ?, ?, ?, ?, ?, ?, ?); select scope_identity()]
source=nhibernate
sqlstring=insert into subscription (membershipid, subscription_number, productid, createtime, audittime, adminid, remarks, state) values (?, ?, ?, ?, ?, ?, ?, ?); select scope_identity()
stacktrace:
在 nhibernate.id.insert.abstractreturningdelegate.performinsert(sqlcommandinfo insertsql, isessionimplementor session, ibinder binder)
在 nhibernate.persister.entity.abstractentitypersister.insert(object[] fields, boolean[] notnull, sqlcommandinfo sql, object obj, isessionimplementor session)
在 nhibernate.persister.entity.abstractentitypersister.insert(object[] fields, object obj, isessionimplementor session)
在 nhibernate.action.entityidentityinsertaction.execute()
在 nhibernate.engine.actionqueue.execute(iexecutable executable)
在 nhibernate.event.default.abstractsaveeventlistener.performsaveorreplicate(object entity, entitykey key, ientitypersister persister, boolean useidentitycolumn, object anything, ieventsource source, boolean requiresimmediateidaccess)
在 nhibernate.event.default.abstractsaveeventlistener.performsave(object entity, object id, ientitypersister persister, boolean useidentitycolumn, object anything, ieventsource source, boolean requiresimmediateidaccess)
在 nhibernate.event.default.abstractsaveeventlistener.savewithgeneratedid(object entity, string entityname, object anything, ieventsource source, boolean requiresimmediateidaccess)
在 nhibernate.event.default.defaultsaveorupdateeventlistener.savewithgeneratedorrequestedid(saveorupdateevent event)
在 nhibernate.event.default.defaultsaveeventlistener.savewithgeneratedorrequestedid(saveorupdateevent event)
在 nhibernate.event.default.defaultsaveorupdateeventlistener.entityistransient(saveorupdateevent event)
在 nhibernate.event.default.defaultsaveeventlistener.performsaveorupdate(saveorupdateevent event)
在 nhibernate.event.default.defaultsaveorupdateeventlistener.onsaveorupdate(saveorupdateevent event)
在 nhibernate.impl.sessionimpl.firesave(saveorupdateevent event)
在 nhibernate.impl.sessionimpl.save(object obj)
在 dayou.yun.biz.dao.subscriptiondao.getsubscriptionlistbyinsert(subscriptionentity subscription) 位置 e:\dayouyun\dayou.yun.biz\dao\subscriptiondao.cs:行号 52
在 dayou.yun.biz.dao.baseapi.subscriptionapi.getsubscriptionlist(subscriptionentity subscription) 位置 e:\dayouyun\dayou.yun.biz\dao\baseapi\subscriptionapi.cs:行号 21
在 dayou.yun.webapi.controllers.ordercontroller.createorder(string ids, int32 deliveryadd, string apiorderproductentity, int32 businesstype, int32 authentiction) 位置 e:\dayouyun\dayou.yun.webapi\controllers\ordercontroller.cs:行号 369
innerexception: system.data.sqlclient.sqlexception
hresult=-2146232060
message=insert 语句与 foreign key 约束"fk_subscription_admin"冲突。该冲突发生于数据库"dayouyun",表"dbo.admin", column 'adminid'。
语句已终止。
source=.net sqlclient data provider
errorcode=-2146232060
class="16"
linenumber=1
number=547
procedure=""
server=192.168.0.132
state=0
stacktrace:
在 system.data.sqlclient.sqlconnection.onerror(sqlexception exception, boolean breakconnection, action`1 wrapcloseinaction)
在 system.data.sqlclient.sqlinternalconnection.onerror(sqlexception exception, boolean breakconnection, action`1 wrapcloseinaction)
在 system.data.sqlclient.tdsparser.throwexceptionandwarning(tdsparserstateobject stateobj, boolean callerhasconnectionlock, boolean asyncclose)
在 system.data.sqlclient.tdsparser.tryrun(runbehavior runbehavior, sqlcommand cmdhandler, sqldatareader datastream, bulkcopysimpleresultset bulkcopyhandler, tdsparserstateobject stateobj, boolean& dataready)
在 system.data.sqlclient.sqldatareader.tryconsumemetadata()
在 system.data.sqlclient.sqldatareader.get_metadata()
在 system.data.sqlclient.sqlcommand.finishexecutereader(sqldatareader ds, runbehavior runbehavior, string resetoptionsstring)
在 system.data.sqlclient.sqlcommand.runexecutereadertds(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, boolean async, int32 timeout, task& task, boolean asyncwrite, sqldatareader ds)
在 system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method, taskcompletionsource`1 completion, int32 timeout, task& task, boolean asyncwrite)
在 system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method)
在 system.data.sqlclient.sqlcommand.executereader(commandbehavior behavior, string method)
在 system.data.sqlclient.sqlcommand.executedbdatareader(commandbehavior behavior)
在 system.data.common.dbcommand.system.data.idbcommand.executereader()
在 nhibernate.adonet.abstractbatcher.executereader(idbcommand cmd)
在 nhibernate.id.identitygenerator.insertselectdelegate.executeandextract(idbcommand insert, isessionimplementor session)
在 nhibernate.id.insert.abstractreturningdelegate.performinsert(sqlcommandinfo insertsql, isessionimplementor session, ibinder binder)
innerexception:
数据库注意id这些数据是我手动插入的
id不是从一开始程序中插入的数据不在但是id自增了:
有人能帮我解决一下吗?