我创建了控制台应用程序、数据库、模型、XML 文件,然后我编写了这段代码
using System;
using System.Reflection;
using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.Driver;
namespace NHibernateDemo
{
internal class Program
{
static void Main(string[] args)
{
try
{
var cfg = new Configuration();
cfg.DataBaseIntegration(x =>
{
x.ConnectionString = "Server=.; Database=NHibernateDemo; Integrated Security = SSPI;";
x.Driver<SqlClientDriver>();
x.Dialect<MsSql2008Dialect>();
});
cfg.AddAssembly(Assembly.GetExecutingAssembly());
var sessionFactory = cfg.BuildSessionFactory();
using (var session = sessionFactory.OpenSession())
using (var tx = session.BeginTransaction())
{
var customers = session.CreateCriteria<Customer>()
.List<Customer>();
foreach (var customer in customers)
{
Console.WriteLine("{0} {1}", customer.FirstName, customer.LastName);
}
tx.Commit();
Console.WriteLine("Enter any key to exit...");
Console.ReadKey();
}
}
catch (Exception e)
{
}
}
}
}
我没有收到任何错误和任何异常,但我也没有从数据库中获得任何信息,只是"Enter any key to exit..."
控制台中的字符串。
怎么了?
UPD
XML 文件
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mappin xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernateDemo"
namespace="NHibernateDemo">
<class name="Customer">
<id name="Id">
<generator class="native" />
</id>
<property name="FirstName"/>
<property name="LastName"/>
</class>
</hibernate-mappin>