NHibernate version: Build 1.0.2.0
DatabaseMSSql 2000
IDE Visual Studio 2005
Hi,
I am new to NHibernate and I have manage to work my way though most of my issues, but I am stuck right now on saving money amounts to the DB. I have mapped the property as a Decimal (19, 4) in my mapping file and the property Type is Decimal. The DB Type is Money
At first I thought the form was doing some thing strange, so I am building an object in the code and saving it.
DTP.Data.Bond bond = new DTP.Data.Bond();
bond.BondName = "bob";
bond.Bond_ID = "2";
...
...
bond.OriginalAmt = new Decimal(50.0);
bond.AmendedAmt = new Decimal(60.0);
bond.AmendmentDate = DateTime.Today;
DTP.Controller.BondController bc = new BondController();
bc.Save(bond);
The controller just is calling a my session controller and using the m_session to call SaveOrUpdate(bond) with my bond.
All the files are listed below along with the SQL
Thanks for any help,
John
The SQL that comes out is
INSERT INTO Track.dbo.Bond (State, AmendedAmt, LetterDate, ContactName, IssueDate, AmendmentDate, CompletionPerc, Comments, City, SendBy, SuretyCompID, Fax, Zip, AnnualPremium, Address2, Obligee, ContigencyPerc, Address1, BondTypeID, ExpirationDate, Email, Project_ID, BondID, BrokerID, BondName, Phone, OriginalAmt) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15, @p16, @p17, @p18, @p19, @p20, @p21, @p22, @p23, @p24, @p25, @p26); select SCOPE_IDENTITY()
@p0 = 'NC'
@p1 = '60'
@p2 = '1/1/0001 12:00:00 AM'
@p3 = 'John'
@p4 = '1/1/0001 12:00:00 AM'
@p5 = '6/28/2006 12:00:00 AM'
@p6 = '0'
@p7 = ''
@p8 = 'Durham'
@p9 = '0'
@p10 = ''
@p11 = ''
@p12 = '27329'
@p13 = '0'
@p14 = ''
@p15 = ''
@p16 = '0'
@p17 = '123 Somestreet Dr.'
@p18 = ''
@p19 = '1/1/0001 12:00:00 AM'
@p20 =
'jlucas@yahoo.com'
@p21 = ''
@p22 = '2'
@p23 = ''
@p24 = 'bob'
@p25 = '9191234567'
@p26 = '50'
Here is the mapping file.
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DTP.Data.Bond,DTP" table="Bond">
<id name="Id" column="Bond_ID" type="Int64" unsaved-value="0">
<generator class="native"/>
</id>
<bag name="BondLetterHistList" inverse="true" lazy="true" >
<key column="Bond_ID" />
<one-to-many class="DTP.Data.BondLetterHist,DTP" />
</bag>
<property column="BondID" type="String" name="Bond_ID" not-null="true" length="20" />
<property column="BondName" type="String" name="BondName" length="50" />
<many-to-one name="BondType" column="BondTypeID" class="DTP.Data.BondType,DTP" />
<many-to-one name="ProjectId" column="Project_ID" class="DTP.Data.Project,DTP" />
<many-to-one name="SuretyComp" column="SuretyCompID" class="DTP.Data.SuretyComp,DTP" />
<many-to-one name="Broker" column="BrokerID" class="DTP.Data.Broker,DTP" />
<property column="Address1" type="String" name="Address1" length="50" />
<property column="Address2" type="String" name="Address2" length="50" />
<property column="City" type="String" name="City" length="50" />
<property column="State" type="String" name="State" />
<property column="Zip" type="String" name="Zip" length="10" />
<property column="Phone" type="String" name="Phone" length="10" />
<property column="Fax" type="String" name="Fax" length="10" />
<property column="Email" type="String" name="Email" length="50" />
<property column="ContactName" type="String" name="ContactName" length="50" />
<property column="Obligee" type="String" name="Obligee" length="50" />
<property column="IssueDate" type="DateTime" name="IssueDate" />
<property column="ExpirationDate" type="DateTime" name="ExpirationDate" />
<property column="OriginalAmt" type="Decimal (19,4)" name="OriginalAmt" not-null="true" />
<property column="AmendedAmt" type="Decimal (19,4)" name="AmendedAmt" not-null="true" />
<property column="AmendmentDate" type="DateTime" name="AmendmentDate" not-null="true" />
<property column="ContigencyPerc" type="Double" name="ContigencyPerc" />
<property column="CompletionPerc" type="Double" name="CompletionPerc" />
<property column="AnnualPremium" type="Decimal (19,4)" name="AnnualPremium" not-null="true" />
<property column="Comments" type="String" name="Comments" length="2147483647" />
<property column="SendBy" type="Byte" name="SendBy" />
<property column="LetterDate" type="DateTime" name="LetterDate" />
</class>
</hibernate-mapping>
And the Class File.
/*
insert license info here
*/
using System;
using System.Collections;
using Lucas.Business;
namespace DTP.Data
{
/// <summary>
/// Generated by MyGeneration using the NHibernate Object Mapping template
/// </summary>
[Serializable]
public sealed class Bond : BaseObject
{
#region Private Members
private bool m_isChanged;
private IList m_BondLetterHistList;
private string m_bond;
private string m_bondname;
private BondType m_bondtype;
private Project m_project_;
private SuretyComp m_suretycomp;
private Broker m_broker;
private string m_address1;
private string m_address2;
private string m_city;
private string m_state;
private string m_zip;
private string m_phone;
private string m_fax;
private string m_email;
private string m_contactname;
private string m_obligee;
private DateTime m_issuedate;
private DateTime m_expirationdate;
private Decimal m_originalamt;
private Decimal m_amendedamt;
private DateTime m_amendmentdate;
private double m_contigencyperc;
private double m_completionperc;
private Decimal m_annualpremium;
private string m_comments;
private byte m_sendby;
private DateTime m_letterdate;
#endregion
#region Default ( Empty ) Class Constuctor
/// <summary>
/// default constructor
/// </summary>
public Bond()
{
m_id = 0;
m_BondLetterHistList = new ArrayList();
m_bond = String.Empty;
m_bondname = String.Empty;
m_bondtype = new BondType();
m_project_ = new Project();
m_suretycomp = new SuretyComp();
m_broker = new Broker();
m_address1 = String.Empty;
m_address2 = String.Empty;
m_city = String.Empty;
m_state = String.Empty;
m_zip = String.Empty;
m_phone = String.Empty;
m_fax = String.Empty;
m_email = String.Empty;
m_contactname = String.Empty;
m_obligee = String.Empty;
m_issuedate = DateTime.MinValue;
m_expirationdate = DateTime.MinValue;
m_originalamt = new Decimal(0.0);
m_amendedamt = new Decimal(0.0);
m_amendmentdate = DateTime.MinValue;
m_contigencyperc = new double();
m_completionperc = new double();
m_annualpremium = new Decimal(0.0);
m_comments = String.Empty;
m_sendby = new byte();
m_letterdate = DateTime.MinValue;
}
#endregion // End of Default ( Empty ) Class Constuctor
#region Public Properties
/// <summary>
///
/// </summary>
public override long Id
{
get { return m_id; }
set { m_id = value; }
}
public IList BondLetterHistList
{
get
{
return m_BondLetterHistList;
}
set
{
m_BondLetterHistList = value;
}
}
/// <summary>
///
/// </summary>
public string Bond_ID
{
get { return m_bond; }
set
{
if( value == null )
throw new ArgumentOutOfRangeException("Null value not allowed for Bond", value, "null");
if( value.Length > 20)
throw new ArgumentOutOfRangeException("Invalid value for Bond", value, value.ToString());
m_isChanged |= (m_bond != value); m_bond = value;
}
}
/// <summary>
///
/// </summary>
public string BondName
{
get { return m_bondname; }
set
{
if( value != null && value.Length > 50)
throw new ArgumentOutOfRangeException("Invalid value for BondName", value, value.ToString());
m_isChanged |= (m_bondname != value); m_bondname = value;
}
}
/// <summary>
///
/// </summary>
public BondType BondType
{
get { return m_bondtype; }
set
{
m_isChanged |= ( m_bondtype != value );
m_bondtype = value;
}
}
/// <summary>
///
/// </summary>
public Project ProjectId
{
get { return m_project_; }
set
{
m_isChanged |= ( m_project_ != value );
m_project_ = value;
}
}
/// <summary>
///
/// </summary>
public SuretyComp SuretyComp
{
get { return m_suretycomp; }
set
{
m_isChanged |= ( m_suretycomp != value );
m_suretycomp = value;
}
}
/// <summary>
///
/// </summary>
public Broker Broker
{
get { return m_broker; }
set
{
m_isChanged |= ( m_broker != value );
m_broker = value;
}
}
/// <summary>
///
/// </summary>
public string Address1
{
get { return m_address1; }
set
{
if( value != null && value.Length > 50)
throw new ArgumentOutOfRangeException("Invalid value for Address1", value, value.ToString());
m_isChanged |= (m_address1 != value); m_address1 = value;
}
}
/// <summary>
///
/// </summary>
public string Address2
{
get { return m_address2; }
set
{
if( value != null && value.Length > 50)
throw new ArgumentOutOfRangeException("Invalid value for Address2", value, value.ToString());
m_isChanged |= (m_address2 != value); m_address2 = value;
}
}
/// <summary>
///
/// </summary>
public string City
{
get { return m_city; }
set
{
if( value != null && value.Length > 50)
throw new ArgumentOutOfRangeException("Invalid value for City", value, value.ToString());
m_isChanged |= (m_city != value); m_city = value;
}
}
/// <summary>
///
/// </summary>
public string State
{
get { return m_state; }
set
{
m_isChanged |= ( m_state != value );
m_state = value;
}
}
/// <summary>
///
/// </summary>
public string Zip
{
get { return m_zip; }
set
{
if( value != null && value.Length > 10)
throw new ArgumentOutOfRangeException("Invalid value for Zip", value, value.ToString());
m_isChanged |= (m_zip != value); m_zip = value;
}
}
/// <summary>
///
/// </summary>
public string Phone
{
get { return m_phone; }
set
{
if( value != null && value.Length > 10)
throw new ArgumentOutOfRangeException("Invalid value for Phone", value, value.ToString());
m_isChanged |= (m_phone != value); m_phone = value;
}
}
/// <summary>
///
/// </summary>
public string Fax
{
get { return m_fax; }
set
{
if( value != null && value.Length > 10)
throw new ArgumentOutOfRangeException("Invalid value for Fax", value, value.ToString());
m_isChanged |= (m_fax != value); m_fax = value;
}
}
/// <summary>
///
/// </summary>
public string Email
{
get { return m_email; }
set
{
if( value != null && value.Length > 50)
throw new ArgumentOutOfRangeException("Invalid value for Email", value, value.ToString());
m_isChanged |= (m_email != value); m_email = value;
}
}
/// <summary>
///
/// </summary>
public string ContactName
{
get { return m_contactname; }
set
{
if( value != null && value.Length > 50)
throw new ArgumentOutOfRangeException("Invalid value for ContactName", value, value.ToString());
m_isChanged |= (m_contactname != value); m_contactname = value;
}
}
/// <summary>
///
/// </summary>
public string Obligee
{
get { return m_obligee; }
set
{
if( value != null && value.Length > 50)
throw new ArgumentOutOfRangeException("Invalid value for Obligee", value, value.ToString());
m_isChanged |= (m_obligee != value); m_obligee = value;
}
}
/// <summary>
///
/// </summary>
public DateTime IssueDate
{
get { return m_issuedate; }
set
{
m_isChanged |= ( m_issuedate != value );
m_issuedate = value;
}
}
/// <summary>
///
/// </summary>
public DateTime ExpirationDate
{
get { return m_expirationdate; }
set
{
m_isChanged |= ( m_expirationdate != value );
m_expirationdate = value;
}
}
/// <summary>
///
/// </summary>
public Decimal OriginalAmt
{
get { return m_originalamt; }
set
{
m_isChanged |= ( m_originalamt != value );
m_originalamt = value;
}
}
/// <summary>
///
/// </summary>
public Decimal AmendedAmt
{
get { return m_amendedamt; }
set
{
m_isChanged |= ( m_amendedamt != value );
m_amendedamt = value;
}
}
/// <summary>
///
/// </summary>
public DateTime AmendmentDate
{
get { return m_amendmentdate; }
set
{
m_isChanged |= ( m_amendmentdate != value );
m_amendmentdate = value;
}
}
/// <summary>
///
/// </summary>
public double ContigencyPerc
{
get { return m_contigencyperc; }
set
{
m_isChanged |= ( m_contigencyperc != value );
m_contigencyperc = value;
}
}
/// <summary>
///
/// </summary>
public double CompletionPerc
{
get { return m_completionperc; }
set
{
m_isChanged |= ( m_completionperc != value );
m_completionperc = value;
}
}
/// <summary>
///
/// </summary>
public Decimal AnnualPremium
{
get { return m_annualpremium; }
set
{
m_isChanged |= ( m_annualpremium != value );
m_annualpremium = value;
}
}
/// <summary>
///
/// </summary>
public string Comments
{
get { return m_comments; }
set
{
if( value != null && value.Length > 2147483647)
throw new ArgumentOutOfRangeException("Invalid value for Comments", value, value.ToString());
m_isChanged |= (m_comments != value); m_comments = value;
}
}
/// <summary>
///
/// </summary>
public byte SendBy
{
get { return m_sendby; }
set
{
m_isChanged |= (m_sendby != value); m_sendby = value;
}
}
/// <summary>
///
/// </summary>
public DateTime LetterDate
{
get { return m_letterdate; }
set
{
m_isChanged |= ( m_letterdate != value );
m_letterdate = value;
}
}
/// <summary>
/// Returns whether or not the object has changed it's values.
/// </summary>
public bool IsChanged
{
get { return m_isChanged; }
}
#endregion
#region Equals And HashCode Overrides
/// <summary>
/// local implementation of Equals based on unique value members
/// </summary>
public override bool Equals( object obj )
{
if( this == obj ) return true;
if( ( obj == null ) || ( obj.GetType() != this.GetType() ) ) return false;
Bond castObj = (Bond)obj;
return ( castObj != null ) &&
(this.m_id == castObj.m_id);
}
/// <summary>
/// local implementation of GetHashCode based on unique value members
/// </summary>
public override int GetHashCode()
{
int hash = 57;
hash = 27 * hash * m_id.GetHashCode();
return hash;
}
#endregion
}
}