首页 新闻 会员 周边 捐助

NHibernate

0
悬赏园豆:5 [待解决问题]

捕捉到 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, Action1 wrapCloseInAction) 在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 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:
这么一个问题不知道怎么解决??????求大神帮忙!!!!

ccc#的主页 ccc# | 初学一级 | 园豆:197
提问于:2018-12-07 10:46
< >
分享
所有回答(1)
0

检查下这sql对不对:
INSERT INTO Subscription (MembershipId, Subscription_number, ProductId, CreateTime, AuditTime, AdminId, Remarks, State) VALUES (?, ?, ?, ?, ?, ?, ?, ?);

会长 | 园豆:12463 (专家六级) | 2018-12-07 11:15

这个select 是对的,我在数据库中试了,只是插入的数据是我自己写的
INSERT INTO Subscription (MembershipId, Subscription_number, ProductId, CreateTime, State) VALUES ('2', '99', '2071', '2018-12-6', '1')
INSERT INTO Subscription (MembershipId, Subscription_number, ProductId, CreateTime, AuditTime, AdminId, Remarks, State) VALUES (?, ?, ?, ?, ?, ?, ?, ?)

支持(0) 反对(0) ccc# | 园豆:197 (初学一级) | 2018-12-07 11:20

@ccc#: 看看真实的值有什么区别,也许数据类型不对,也许是超过了字段最大长度等,有可能吗?

支持(0) 反对(0) 会长 | 园豆:12463 (专家六级) | 2018-12-07 11:21

@ccc#: https://blog.csdn.net/taoyuan0908/article/details/5197895

支持(0) 反对(0) 会长 | 园豆:12463 (专家六级) | 2018-12-07 11:22

@会长: 我调试的时候看了,传进去的值都是合理的,在数据库中手动插入可以,但是用代码插入进去就报这个错了。

支持(0) 反对(0) ccc# | 园豆:197 (初学一级) | 2018-12-07 11:23

@ccc#: 那就无能为力了,也许上传的能复现问题的demo项目有点用

支持(0) 反对(0) 会长 | 园豆:12463 (专家六级) | 2018-12-07 11:25

@会长: 你去我的博客看一下,我发的比较详细

支持(0) 反对(0) ccc# | 园豆:197 (初学一级) | 2018-12-07 11:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册