您好我正在使用sqllite运行我的系统的单元测试,所以它在内存中 但不知何故我遇到异常是异常和测试正在进行
Test method Cirrus.Data.Test.ItemPersistanceTest.MapHMOAssetEquipment threw exception:
NHibernate.Exceptions.GenericADOException: could not insert: [Cirrus.Domain.HMOAssetEquipmentMapping#101][SQL: /* insert Cirrus.Domain.HMOAssetEquipmentMapping */ INSERT INTO HMOAssetEquipmentMapping (Version, AssetEquipmentId, HealthMaintenanceOrganizationId, HMOAssetEquipmentCode, HMOAssetEquipmentName, Id) VALUES (?, ?, ?, ?, ?, ?)] ---> System.Data.SQLite.SQLiteException: SQLite error
foreign key mismatch
at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, ref String strRemain) in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLite3.cs: line 417
at System.Data.SQLite.SQLiteCommand.BuildNextCommand() in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteCommand.cs: line 259
at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index) in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteCommand.cs: line 266
at System.Data.SQLite.SQLiteDataReader.NextResult() in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteDataReader.cs: line 1062
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave) in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteDataReader.cs: line 108
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior) in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteCommand.cs: line 541
at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery() in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteCommand.cs: line 570
at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\AdoNet\AbstractBatcher.cs: line 216
at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\AdoNet\NonBatchingBatcher.cs: line 40
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs: line 2649
--- End of inner exception stack trace ---
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs: line 2669
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs: line 3055
at NHibernate.Action.EntityInsertAction.Execute() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Action\EntityInsertAction.cs: line 59
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs: line 136
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs: line 126
at NHibernate.Engine.ActionQueue.ExecuteActions() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs: line 169
at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs: line 249
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\DefaultFlushEventListener.cs: line 19
at NHibernate.Impl.SessionImpl.Flush() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs: line 1489
at NHibernate.Transaction.AdoTransaction.Commit() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Transaction\AdoTransaction.cs: line 190
at Cirrus.Data.Test.ItemPersistanceTest.MapHMOAssetEquipment() in ItemPersistanceTest.cs: line 642
这是我的单元测试
[TestMethod]
public void MapHMOAssetEquipment()
{
object id;
IAssetEquipmentDao assetEquipmentdao = new AssetEquipmentDao(SessionFactory);
IHMODao hmodao = new HMODao(SessionFactory);
IHMOAssetEquipmentMappingDao hmoAssetEquipmentmappingdao = new HMOAssetEquipmentMappingDao(SessionFactory);
var assetEquipment = new AssetEquipment { Code = "Code", Name = "AssetEquipment Name" };
var hmo = new HealthMaintenanceOrganization { Name = "HMO Name" };
var hmoAssetEquipmentmapping = new HMOAssetEquipmentMapping { HMOAssetEquipmentCode = "HMO AssetEquipment Code", HealthMaintenanceOrganization = hmo, HMOAssetEquipmentName = "HMO AssetEquipment Name", AssetEquipment = assetEquipment };
using (var tx = Session.BeginTransaction())
{
assetEquipmentdao.Save(assetEquipment);
hmodao.Save(hmo);
hmoAssetEquipmentmappingdao.Save(hmoAssetEquipmentmapping);
tx.Commit();
id = hmoAssetEquipmentmapping.Id;
}
using (Session.BeginTransaction())
{
var x = hmoAssetEquipmentmappingdao.GetById(id);
Assert.AreEqual(x.HealthMaintenanceOrganization.Id, hmo.Id);
Assert.AreEqual(x.AssetEquipment.Id, assetEquipment.Id);
Assert.AreEqual(x.HMOAssetEquipmentCode, hmoAssetEquipmentmapping.HMOAssetEquipmentCode);
Assert.AreEqual(x.HMOAssetEquipmentName, hmoAssetEquipmentmapping.HMOAssetEquipmentName);
}
}
不知何故,当我尝试在MSSQL中运行它时,它可以工作,但不能在SQL Lite中运行,
有人遇到过这个问题吗? 顺便说一句,我使用Nhibernate 3.2和SQLLite 1.0.77.0