2011-07-22 7 views
0

私はoracle dbで動作するnhibernateを持っています。私は、メモリDB内でsqliteを使用してクエリロジックをテストしようとしています。私は、この問題に関するWeb上のすべての答えを読んで理解し、確認していると信じています。そのうちのいくつかは数回あります:)SqLite in memory DBとNHibernate

SQLiteエラーが発生していません。このようなテーブルはありません: 私もddlコマンドSchemaExportの呼び出しで

ここには、私が関連していると感じる設定のビットがあります。

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping assembly="myassmebly" namespace="myns" xmlns="urn:nhibernate-mapping-2.2"> 
<class name="ComponentGroup" table="TBL_COMPONENT_GROUP" lazy="true" > 
<id name="Id" column="N_COMPONENT_GROUP_ID" type="int"> 
    <generator class="native" /> 
</id> 
<property name="AssemblyFacilityId" column="N_ASSEMBLY_FACILITY_ID" type="int" not-null="true" /> 
<property name="Name" column="C_COMPONENT_GROUP_NAME" type="string" not-null="true" /> 
<property name="IsDiscontinued" column="N_DISCONTINUED_FLAG" type="bool" not-null="true" /> 
</class> 
</hibernate-mapping> 

マイPOCO

public class ComponentGroup 
{ 
    public virtual int Id { get; set; } 
    public virtual int AssemblyFacilityId { get; set; } 
    public virtual string Name { get; set; } 
    public virtual bool IsDiscontinued { get; set; } 
} 

私が使用しているのInnerException

InnerException: System.Data.SQLite.SQLiteException 
    Message=SQLite error 
    no such table: TBL_COMPONENT_GROUP 
    Source=System.Data.SQLite 
    ErrorCode=-2147467259 
    StackTrace: 
     at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, 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) 

: このコードは、すべて同じ方法

cfg = new Configuration() 
.SetProperty(Environment.ReleaseConnections, "on_close") 
.SetProperty(Environment.Dialect, typeof(SQLiteDialect).AssemblyQualifiedName) 
.SetProperty(Environment.ConnectionDriver, typeof(SQLite20Driver).AssemblyQualifiedName) 
.SetProperty(Environment.ConnectionString, "Data Source=:memory:;Version=3;New=True") 
.SetProperty(Environment.ProxyFactoryFactoryClass, typeof(ProxyFactoryFactory).AssemblyQualifiedName) 
.SetProperty(Environment.ShowSql, "true") 
.SetProperty(Environment.ConnectionProvider, typeof(NHibernate.Connection.DriverConnectionProvider).AssemblyQualifiedName); 
cfg.AddAssembly("MyAssembly"); 
_sessionFactory = cfg.BuildSessionFactory(); 
_session = _sessionFactory.OpenSession(); 
new SchemaExport(cfg).Execute(true, true, false, _session.Connection, Console.Out); <--don't see any ddl commands here 
var q = from c in _session.Query<ComponentGroup>() 
where !c.IsDiscontinued 
select c; 
var z = q.ToList(); //<--get error here 

マイ.hbm.xmlからですNHibernateバージョン3.1.0.4、SyステムDate.SQLiteバージョン2.0.50727

+0

hbm.xmlマッピングが実際に埋め込みリソースに設定されているかどうかを確認できますか? – Firo

+0

これは、同じhbmがoracleセッションで動作する – Wieknot

答えて

1

この修正は、 新しいSchemaExport(cfg).Execute(true、true、false、_session.Connection、Console.Out);を置き換えます。 と 新しいSchemaExport(cfg).Execute(true、true、false、_session.Connection、null);

本当にわかりませんが、エクスポートされたテーブルに行を挿入するコードを追加しました。これは期待どおりに機能しました。

次に、Console.Outパラメータを元に戻し、「閉じたTextWriterに書き込めません」というメッセージが表示されます。エラー。