I create the Customer.cs model, the Customer.cs XML file, in the SQL Managment Studio I create the NHibernateDemo database with the Customer table in it. I connect DB to the project through Server Explorer.
Further I write such code in the program.

 using System; using System.Reflection; using NHibernate.Cfg; using NHibernate.Dialect; using NHibernate.Driver; namespace NHibernateDemo { internal class Program { static void Main(string[] args) { var cfg = new Configuration(); cfg.DataBaseIntegration(x => { x.ConnectionString = "Server=OLDBLACK; 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(); } } } } 

but when I start it, nothing is output to debug, except for the inscription "Enter any key to exit ..." As I understand it, something is wrong with the connection string? How to fix it?

    1 answer 1

    For the Customer.nbm.xml file, you need to put the embedded resource in the properties.