Reputation: 3254
I created console application, database, model, XML-file and then I wrote this code
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)
{
}
}
}
}
I didn't get any error and any exception, but I didn't get any information from database too, just string "Enter any key to exit..."
in console.
What's wrong?
UPD
XML-file
<?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>
Upvotes: 2
Views: 448
Reputation: 6875
The root tag of a mapping XML file has to be hibernate-mapping
(note the "g" at the end).
Upvotes: 1
Reputation: 27944
Have you added the xml mapping files to the Assembly.GetExecutingAssembly())
? You have to make the embedded resource. Otherwise you will have the behavoir you are describing.
Go to the properties of the files to change the build action.
Upvotes: 2