Hi guys,
I have this error on this. I need help where the error have been caused.
Below are the sections of the codes
On Program.cs
//Create Session and Transaction
ISession session = sessionFactory.OpenSession();
ITransaction tx = session.BeginTransaction();
//Insert records
Contact ordCntct = new Contact("Martha", "Washington", "
[email protected]");
Address ordAddr = new Address("1600 Pennsylvania Ave, NW", null,
"Washington, DC", "20500");
ordAddr.AddressContact = ordCntct;
ordCntct.ContactAddress = new List<Address>();
ordCntct.ContactAddress.Add(ordAddr);
OrderHeader header = new OrderHeader();
header.Number = "0000001";
header.OrderDate = DateTime.Now;
header.BillToContact = ordCntct;
header.BillToAddress = ordAddr;
header.ShipToContact = ordCntct;
header.ShipToAddress = ordAddr;
//session.SaveOrUpdate(header);
session.Save(header);
tx.Commit();
On Contact.cs
#region Properties
private int _ID;
private string _lastName;
private string _firstName;
private string _email;
private IList<Phone> _contactPhone;
private IList<Address> _contactAddress;
private IList<OrderHeader> _billToContacts;
private IList<OrderHeader> _shipToContacts;
public virtual IList<OrderHeader> ShipToContacts
{
get { return _shipToContacts; }
set { _shipToContacts = value; }
}
public virtual IList<OrderHeader> BillToContacts
{
get { return _billToContacts; }
set { _billToContacts = value; }
}
public virtual IList<Address> ContactAddress
{
get { return _contactAddress; }
set { _contactAddress = value; }
}
public virtual IList<Phone> ContactPhone
{
get { return _contactPhone; }
set { _contactPhone = value; }
}
public virtual string Email
{
get { return _email; }
set { _email = value; }
}
public virtual string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
public virtual string LastName
{
get { return _lastName; }
set { _lastName = value; }
}
public virtual int ID
{
get { return _ID; }
set { _ID = value; }
}
#endregion
#region Constructor
public Contact()
{ }
public Contact(string lastName, string firstName, string email) :
this()
{
this.LastName = lastName;
this.FirstName = firstName;
this.Email = email;
}
#endregion
On Contact.hbm.xml
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Ordering.Data"
assembly="Ordering.Data">
<class name="Ordering.Data.Contact, Ordering.Data"
table="Contact">
<id name="ID">
<column name="ID" sql-type="Int32"/>
<generator class="native"/>
</id>
<property name="LastName" type="String"/>
<property name="FirstName" type="String"/>
<property name="Email" type="String"/>
<!--Many to Many Relationship-->
<!--One to Many Relationship-->
<bag name="BillToContacts" inverse="true"
lazy="true" cascade="all-delete-orphan">
<key column="BillToContact_ID"/>
<one-to-many class="OrderHeader"/>
</bag>
<bag name="ShipToContacts" inverse="true"
lazy="true" cascade="all-delete-orphan">
<key column="ShipToContact_ID"/>
<one-to-many class="OrderHeader"/>
</bag>
<bag name="ContactAddress" inverse="true"
lazy="true" cascade="all-delete-orphan">
<key column="Contact_ID"/>
<one-to-many class="Address"/>
</bag>
<bag name="ContactPhone" table="Contact_Phone" inverse="false"
lazy="true" cascade="none">
<key>
<column name="Contact_ID" length="4" sql-type="Int32"
not-null="true"/>
</key>
<many-to-many class="Phone">
<column name="Phone_ID" length="4" sql-type="Int32"
not-null="true"/>
</many-to-many>
</bag>
</class>
</hibernate-mapping>
Hope you guys can help me.
--
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.