Fluent NHibernate with SQLite
I am using SQLite for unit test.
private ISession _session;
[SetUp]
public virtual void SetUp()
开发者_如何转开发{
string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies();
configuration = NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies,
new AutoPersistenceModelGenerator().Generate(),
@"C:\Sharp Architecture\SharpArchitecture_1_6_FullSourceAndTemplates (1)\src\NorthwindSample\tests\Northwind.Tests\Hibernate.cfg.xml");
_session = NHibernateSession.GetDefaultSessionFactory().OpenSession();
new SchemaExport(configuration).Execute(false, true, false, _session.Connection, null);
}
[TearDown]
public virtual void TearDown()
{
NHibernateSession.CloseAllSessions();
NHibernateSession.Reset();
}
[Test]
public void CanConfirmDatabaseMatchesMappings()
{
var allClassMetadata = NHibernateSession.GetDefaultSessionFactory().GetAllClassMetadata();
foreach (var entry in allClassMetadata)
{
NHibernateSession.Current.CreateCriteria(entry.Value.GetMappedClass(EntityMode.Poco))
.SetMaxResults(0).List();
}
}
I am getting the following exception.
NHibernate.ADOException : could not execute query
[ SELECT this_.CategoryID as CategoryID0_0_, this_.CategoryName as Category2_0_0_ FROM Categories this_ limit 0 ]
[SQL: SELECT this_.CategoryID as CategoryID0_0_, this_.CategoryName as Category2_0_0_ FROM Categories this_ limit 0]
----> System.Data.SQLite.SQLiteException : SQLite error
no such table: Categories
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
at NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor session)
at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results)
at NHibernate.Impl.CriteriaImpl.List(IList results)
at NHibernate.Impl.CriteriaImpl.List()
at Tests.Northwind.Data.NHibernateMaps.MappingIntegrationTests.CanConfirmDatabaseMatchesMappings() in MappingIntegrationTests.cs: line 50
--SQLiteException
at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, ref String strRemain)
at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
I am using Sharp Architecture. Thanks, Nabin
Take a look at the class:
FluentNHibernate.Testing.SingleConnectionSessionSourceForSQLiteInMemoryTesting
It has a BuildSchema() method.
精彩评论