hi
I'm very new to NHibernate, so forgive me if i've missed something
very obvious.
I have created a SQL2008 DB with a customers table - all the usual
name, email, address, dob etc nothing overly special.
I then created a c# sharp object library for my business logic -
domain model class called customer with related members to the db
table.
I created a mapping hbm.xml correctly.
Then i created a webapp with references all the required dll etc.
My test page creates a new customer object, saves it to the db, and
then loads the data basck form db into a second cusotmer object -
success! Thank you very much.
I then modify my test to load a specific ID customer from the db, but
it fails - "Specified cast is not valid."
How can this be when the row has already been loaded in a previous
NHibernate session and the data has not been modified in between?!
Any and all help on this is much appreciated.
Thanks,
Pierce
Some code etc:
==============================================
Relevant partial of Customer class
public class Customer
{
#region Constructors
/// <summary>
/// Creates a 'blank' Customer, not yet saved to database
/// </summary>
public Customer()
{
}
/// <summary>
/// Retrieves an existing Customer from the database
/// </summary>
/// <param name="RetrieveID">The Unique key field of the
customer you wish to load from database</param>
public Customer(int RetrieveID)
{
Customer retrievedCustomer =
NHibernateHttpModule.CurrentSession.Get<Customer>(RetrieveID);
// all members get set correctly
}
// many public virtual equivs of the private members
private int _iD;
private string _email = "";
private Titles _title = Titles.Unknown;
private string _forenames = "";
private string _surname = "";
private string _addressLine1 = "";
/// <summary>
/// Saves any modifications to this Customer back to the
database
/// </summary>
public virtual void Save()
{
using (ITransaction wrapper =
NHibernateHttpModule.CurrentSession.BeginTransaction())
{
NHibernateHttpModule.CurrentSession.Save(this);
wrapper.Commit();
}
}
===========================
mapping file
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="CRM.Model" namespace="CRM.Model">
<class name="Customer" table="Customers">
<id name="ID" column="ID" access="nosetter.camelcase-
underscore" type="Int32">
<generator class="native"/>
</id>
<property name="Email" column="Email" type="String"
access="property" />
<property name="Title" column="Title" type="String"
access="property" />
<property name="Forenames" column="Forenames" type="String"
access="property" />
<property name="Surname" column="Surname" type="String"
access="property" />
<property name="AddressLine1" column="AddressLine1"
type="String" access="property" />
</class>
</hibernate-mapping>
============================
test web page code behind
Customer bob = new Customer();
bob.Forenames = "Robert";
bob.Surname = "Robertson";
bob.Email = "[email protected]";
bob.PostCode = "EC1R 2AB";
bob.Save
Customer newBob = new Customer(bob.ID);
^ this works ok!
v this does not
customer bobby = new Customer(1020);
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.