This is my User class file with the mapping file listed at the end. The extra 'bag' tags at the end represent the other tables that I will be working with in the database. I currently have them commented out.
Code:
User.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace Lifecloud.Business
{
public class User :BusinessBase
{
#region Member Variables
private int m_userid = 0;
private string m_firstname = "";
private string m_midinitial = "";
private string m_lastname = "";
private string m_emailaddress = "";
private string m_status = "";
private string m_logonid = "";
private string m_gender = "";
private string m_age = "";
private DateTime m_datecreated = DateTime.Now;
private DateTime m_datemodified = DateTime.Now;
////private IList m_billings; //for future enhancement
#endregion
#region Constructors
/// <summary>
/// This is a placeholder constructor for NHibernate.
/// A no-argument constructor must be available for NHibernate to create the object.
/// Be sure to call the "primary" constructor so the collections get wired up correctly.
/// </summary>
public User()
{
}
#endregion
#region Properties
public virtual int User_ID
{
get { return m_userid; }
set { m_userid = value; }
}
public virtual string FirstName
{
get { return m_firstname; }
set {
if (value == null)
{
throw new ArgumentNullException("FirstName cannot be set to NULL");
}
m_firstname = value;
}
}
public virtual string MidInitial
{
get { return m_midinitial; }
set { m_midinitial = value; }
}
public virtual string LastName
{
get { return m_lastname; }
set {
if (value == null)
{
throw new ArgumentNullException("LastName cannot be set to null");
}
m_lastname = value;
}
}
public virtual string EmailAddress
{
get { return m_emailaddress; }
set {
if (value == null)
{
throw new ArgumentNullException("EmailAddress cannot be set to null");
}
m_emailaddress = value;
}
}
public virtual string Status
{
get { return m_status; }
set { m_status = value; }
}
public virtual string LogonID
{
get { return m_logonid; }
set { m_logonid = value; }
}
public virtual string Gender
{
get { return m_gender; }
set {
if (value == null)
{
throw new ArgumentNullException("Gender cannot be set to null");
} m_gender = value;
}
}
public virtual string Age
{
get { return m_age; }
set { m_age = value; }
}
public virtual DateTime DateCreated
{
get { return m_datecreated; }
set { m_datecreated = value; }
}
public virtual DateTime DateModified
{
get { return m_datemodified; }
set { m_datemodified = value; }
}
public override int Key
{
get { return this.User_ID; }
}
#endregion
#region Methods
#endregion
}
}
User.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Lifecloud.Business.User, Lifecloud.Business" table="User_ID">
<id name="ID" type="int" column="User_ID" unsaved-value="0">
<generator class="native" />
</id>
<property name="FirstName" column="FirstName" />
<property name="MidInitial" column="MidInitial" />
<property name="LastName" column="LastName" />
<property name="EmailAddress" column="EmailAddress" />
<property name="Status" column="Status" />
<property name="LogonID" column="LogonID" />
<property name="Gender" column="Gender" />
<property name="Age" column="Age" />
<property name="DateCreated" column="DateCreated" />
<property name="DateModified" column="DateModified" />
<!--<bag name="Billings" lazy="true" table="Billing_ID" inverse="true"
access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
<key column="User_ID" />
<one-to-many class="Lifecloud.Core.Domain.Billing_ID, Lifecloud.Core" />
</bag>-->
<!--<bag name="ExerciseStats" lazy="true" table="ExerciseStats_ID" inverse="true"
access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
<key column="User_ID" />
<one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
</bag>
<bag name="CurStats" lazy="true" table="CurStats_ID" inverse="true"
access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
<key column="User_ID" />
<one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
</bag>
<bag name="TargetStats" lazy="true" table="TargetStats_ID" inverse="true"
access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
<key column="User_ID" />
<one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
</bag>
<bag name="MentalStats" lazy="true" table="MentalStats_ID" inverse="true"
access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
<key column="User_ID" />
<one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
</bag>
<bag name="Recipes" lazy="true" table="Recipe_ID" inverse="true"
access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
<key column="User_ID" />
<one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
</bag>
<bag name="Exercises" lazy="true" table="Exercise_ID" inverse="true"
access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
<key column="User_ID" />
<one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
</bag>
<bag name="Articles" lazy="true" table="Article_ID" inverse="true"
access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
<key column="User_ID" />
<one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
</bag>
<bag name="WorkOutPlans" lazy="true" table="WorkOutPlans_ID" inverse="true"
access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
<key column="User_ID" />
<one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
</bag>-->
</class>
</hibernate-mapping>
This is the Billing class with the mapping files at the end.
Code:
Billing.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Lifecloud.Business
{
public class Billing
{
#region Member Variables
private int m_billingid = 0;
private int m_userid;
private string m_billaddress1;
private string m_billaddress2;
private string m_billcity;
private string m_billstate;
private string m_billzip;
private string m_homephone;
private string m_workphone;
private string m_mobilephone;
private string m_billemail;
private string m_creditcardtype;
private string m_creditcardnum;
private string m_ccexpiration;
private string m_ccverify;
private DateTime m_datecreated;
private DateTime m_datemodified;
#endregion
#region Constructors
/// <summary>
/// This is a placeholder constructor for NHibernate.
/// A no-argument constructor must be avilable for NHibernate to create the object.
/// Be sure to call the "primary" constructor so the collections get wired up correctly.
/// Instead of passing null to the primary constructor, I'd recommend passing a
/// "null object": http://www.cs.oberlin.edu/~jwalker/nullObjPattern/.
/// (But passing null keeps things very simple for the example.)
/// </summary>
public Billing() { }
#endregion
#region Properties
/// <summary>
/// Sets up parent/child relationship add/remove scaffolding. So if a child is
/// added to a parent, the parent automatically gets added to the child, and vice versa.
/// </summary>
public int Billing_ID
{
get { return m_billingid; }
set { m_billingid = value; }
}
public int User_ID
{
get { return m_userid; }
set { m_userid = value; }
}
public string BillAddress1
{
get { return m_billaddress1; }
set { m_billaddress1 = value; }
}
public string BillAddress2
{
get { return m_billaddress2; }
set { m_billaddress2 = value; }
}
public string BillCity
{
get { return m_billcity; }
set { m_billcity = value; }
}
public string BillState
{
get { return m_billstate; }
set { m_billstate = value; }
}
public string BillZip
{
get { return m_billzip; }
set { m_billzip = value; }
}
public string HomePhone
{
get { return m_homephone; }
set { m_homephone = value; }
}
public string WorkPhone
{
get { return m_workphone; }
set { m_workphone = value; }
}
public string MobilePhone
{
get { return m_mobilephone; }
set { m_mobilephone = value; }
}
public string BillEmail
{
get { return m_billemail; }
set { m_billemail = value; }
}
public string CreditCardType
{
get { return m_creditcardtype; }
set { m_creditcardtype = value; }
}
public string CreditCardNum
{
get { return m_creditcardnum; }
set { m_creditcardnum = value; }
}
public string CCExpiration
{
get { return m_ccexpiration; }
set { m_ccexpiration = value; }
}
public string CCVerify
{
get { return m_ccverify; }
set { m_ccverify = value; }
}
public DateTime DateCreated
{
get { return m_datecreated; }
}
public DateTime DateModified
{
get { return m_datemodified; }
}
#endregion
#region Methods
#endregion
}
}
Billing.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Lifecloud.Business.Billing, Lifecloud.Business" table="Billing">
<id name="ID" type="int" column="Billing_ID" unsaved-value="0">
<generator class="native" />
</id>
<property name="User_ID" column="User_ID" />
<property name="BillAddress1" column="BillAddress1" />
<property name="BillAddress2" column="BillAddress2" />
<property name="BillCity" column="BillCity" />
<property name="BillState" column="BillState" />
<property name="BillZip" column="BillZip" />
<property name="HomePhone" column="HomePhone" />
<property name="WorkPhone" column="WorkPhone" />
<property name="MobilePhone" column="MobilePhone" />
<property name="BillEmail" column="BillEmail" />
<property name="CreditCardType" column="CreditCardType" />
<property name="CreditCardNum" column="CreditCardNum" />
<property name="CCExpiration" column="CCExpiration" />
<property name="CCVerify" column="CCVerify" />
<property name="DateCreated" column="DateCreated" />
<property name="DateModified" column="DateModified" />
</class>
</hibernate-mapping>
The program stops running in this class module at the line noted. This is not the entire class (let me know if you ned it). I included the complete error message at the end of the code.
Code:
NHibernateHttpModule.cs
protected static ISessionFactory CreateSessionFactory()
{
Configuration config;
ISessionFactory factory;
config = new Configuration();
if (config == null)
{
throw new InvalidOperationException("NHibernate configuration is null.");
}
config.Configure();
factory = config.BuildSessionFactory(); <== This is the line that the following error points to.
NHibernate.PropertyNotFoundException was unhandled by user code
Message="Could not find a setter for property 'ID' in class 'Lifecloud.Business.User'"
Source="NHibernate"
StackTrace:
at NHibernate.Property.BasicPropertyAccessor.GetSetter(Type type, String propertyName)
at NHibernate.Mapping.Property.GetSetter(Type clazz)
at NHibernate.Persister.AbstractEntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory)
at NHibernate.Persister.EntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory)
at NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ISessionFactoryImplementor factory)
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, Settings settings)
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at Lifecloud.DataAccess.NHibernateHttpModule.CreateSessionFactory() in
C:\Lifecloud\Lifecloud.DataAccess\NHibernateHttpModule.cs:line 85
at Lifecloud.DataAccess.NHibernateHttpModule.get_CurrentFactory() in
C:\Lifecloud\Lifecloud.DataAccess\NHibernateHttpModule.cs:line 126
at Lifecloud.DataAccess.NHibernateHttpModule.CreateSession() in
C:\Lifecloud\Lifecloud.DataAccess\NHibernateHttpModule.cs:line 140
at Lifecloud.DataAccess.NHibernateHttpModule.get_CurrentSession() in
C:\Lifecloud\Lifecloud.DataAccess\NHibernateHttpModule.cs:line 187
at Lifecloud.DataAccess.BaseDataAccess..ctor() in C:\Lifecloud\Lifecloud.DataAccess\BaseDataAccess.cs:line 20
at Lifecloud.BusinessFacade.UserFacade.GetUser() in C:\Lifecloud\Lifecloud.BusinessFacade\UserFacade.cs:line 40
at ViewUsers.PopulateUsers() in c:\Lifecloud\Lifecloud.WebUI\ViewUsers.aspx.cs:line 29
at ViewUsers.Page_Load(Object sender, EventArgs e) in c:\Lifecloud\Lifecloud.WebUI\ViewUsers.aspx.cs:line 22
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)