I am running a simple application and right before assigning the properties the application dies. Meaning it just snap out of the debug mode and does nothing. No errors are thrown.
I am using Console App with a class library.
Here is the App.config of the console app:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="nhibernate"
type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
/>
</configSections>
<nhibernate>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"
/>
<add
key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"
/>
<add
key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"
/>
<add
key="hibernate.connection.connection_string"
value="Server=localhost;Database=School;Trusted_Connection=true"
/>
</nhibernate>
</configuration>
Now here is the simple "Customer" class:
using System;
using System.Collections.Generic;
using System.Text;
namespace MyCustomObjects
{
public class Customer
{
private int _customerID;
private string _firstName;
private string _lastName;
public virtual int CustomerID
{
get { return _customerID; }
set { _customerID = value; }
}
public virtual string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
public virtual string LastName
{
get { return _lastName; }
set { _lastName = value; }
}
public virtual bool Save()
{
CustomerManager.Save(this);
return false;
}
}
}
NOTE: For some reason I have to make all the properties virtual :(
Here is the hbm.xml file:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="MyCustomObjects.Customer, MyCustomObjects"
table="Customers">
<id name="CustomerID"
type="Int32">
<generator class="assigned" />
</id>
<property name="FirstName"
type="String" length="40"/>
<property name="LastName"
type="String" length="30"/>
</class>
</hibernate-mapping>
And here is the code used to insert the data:
public static int Save(Customer customer)
{
try
{
Configuration config = new Configuration();
config.AddAssembly("MyCustomObjects");
ISessionFactory factory = config.BuildSessionFactory();
ISession session = factory.OpenSession();
session.Save(customer);
session.Close();
}
catch (Exception ex)
{
string exception = ex.Message + " " + ex.InnerException.Message;
}
return 1;
}
The application dies at session.Save(customer) method.
|