NHibernate (2.1.0) の初心者として、有名な Northwind データベースを使用して最初の単体テストをセットアップしようとしています。テストは次のようになります (構成ファイルはこの質問の最後にあります)。
ISessionFactory sessionFactory=new Configuration().BuildSessionFactory();
ISession session=sessionFactory.OpenSession();
IList<Customer> list=session.CreateCriteria<Customer>().List<Customer>();
Assert.AreEqual(91, list.Count);
問題は、それlist.Count
が常に 0 であることです。
IDbConnection
Sql Server 2008、MS Access、および SQLite で独自のセッションを開こうとしましたが(データベースのセットアップと接続が有効であることを 100% 確信しています)、役に立ちませんでした。- 生成された SQL を VS2008 の出力ウィンドウに表示しようとしましたが (この投稿の下部にある構成ファイルを参照)、何も表示されません。
この段階では、構成が間違っているとしか推測できませんが、修正方法がわかりません。
App.config :
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="dialect">NHibernate.Dialect.SQLiteDialect</property> <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property> <property name="connection.connection_string">Data Source=S:\Work\SVN\src\Northwind\SQL\Northwind.db</property> <property name='proxyfactory.factory_class'>NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> <property name="show_sql">true</property> </session-factory> </hibernate-configuration> <log4net> <appender name="DebugSQL" type="log4net.Appender.TraceAppender"> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> </layout> </appender> <root> <level value="DEBUG" /> <appender-ref ref="DebugSQL" /> </root> </log4net>
Customer.cs :
namespace Northwind.DomainModel.NHibernate { public class Customer { public string CustomerID { get; set; } public string CompanyName { get; set; } public string ContactName { get; set; } public string ContactTitle { get; set; } public string Address { get; set; } public string City { get; set; } public string Region { get; set; } public string PostalCode { get; set; } public string Country { get; set; } public string Phone { get; set; } public string Fax { get; set; } } }
Customer.hbm.xml :
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Northwind.DomainModel" namespace="Northwind.DomainModel.NHibernate" > <class name="Customer" table="Customers"> <id name="CustomerID" column="CustomerID" type="String" length="5"> <generator class="assigned" /> </id> <property name="CompanyName" /> <property name="ContactName" /> <property name="ContactTitle" /> <property name="Address" /> <property name="City" /> <property name="Region" /> <property name="PostalCode" /> <property name="Country" /> <property name="Phone" /> <property name="Fax" /> </class> </hibernate-mapping>