随笔 - 1  文章 - 0 评论 - 28 trackbacks - 0

这是我定义的实体类

对应的数据库表

映射文件

数据访问层写的是插入语句

错误:

捕捉到 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自增了:

有人能帮我解决一下吗?

posted on 2018-12-07 11:18 ccc# 阅读(...) 评论(...) 编辑 收藏