這是我定義的實體類 對應的資料庫表 映射文件 數據訪問層寫的是插入語句 錯誤: 捕捉到 NHibernate.Exceptions.GenericADOException HResult=-2146232832 Message=could not insert: [DaYou.Yun.Entity. ...
這是我定義的實體類
對應的資料庫表
映射文件
數據訪問層寫的是插入語句
錯誤:
捕捉到 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自增了:
有人能幫我解決一下嗎?