Hi all,
I'm runing an NHibernate program, i want it to save the customer details into the database but I get "No row with the given identifier exists[NHibernate_Demo.Customer#10]" error. I got some of the code from the net and other stuff I don't understand as I'm new in NHibernate concept.
Here is my Customer.cs class:
using System; using System.Collections.Generic; using System.Text; using NHibernate; using NHibernate.Cfg; using System.ComponentModel; using System.Data; using System.IO; using System.Data.Sql; using System.Data.SqlClient; using System.Configuration; using System.Diagnostics;
namespace NHibernate_Demo {
class Program { static void Main(string[] args) { //Console.WriteLine("Hello there!"); Console.Write("Please input your ID: "); string CustomerID = Console.ReadLine(); Console.Write("Please input your Company Name: "); string CompanyName = Console.ReadLine(); Console.Write("Please input your Name: "); string ContactName = Console.ReadLine(); Console.Write("Please input your Title: "); string ContactTitle = Console.ReadLine(); Console.Write("Please input your Phone: "); string Phone = Console.ReadLine(); Console.Write("Please input your Alt Phone: "); string AltPhone = Console.ReadLine(); Console.WriteLine("Hello " + ContactName + ". Thank you for registering your information."); Console.Read(); // Loads the NHibernate Types to prepare for Serialization Configuration cfg = new Configuration(); cfg.Configure();
cfg.AddAssembly(typeof(NHibernate_Demo.Customer).Assembly); //cfg.AddClass(typeof(Customer)); //cfg.AddFile("Customer.hbm.xml");
//Opens a session to NHiberbate to allow us to work with objects ISessionFactory sessionsF = cfg.BuildSessionFactory();
//let ISessiionFactory open connection ISession sessionS = sessionsF.OpenSession();
ITransaction transaction = sessionS.BeginTransaction(); { Customer customer = (Customer)sessionS.Load(typeof(Customer), 12); sessionS.Close();
}
} } }
I get an error on this line and I got it from the net.
Customer customer = (Customer)sessionS.Load(typeof(Customer), 12);
I really don't know what to put there for my program to save to the database.
Please, I'd appreciate a solution to this or some hints on what to do.
Thanks.
|