I am using C#.NET w/ .NET 2.0 and MSSQL 2000 and NHibernate 1.0.3. I'm trying to insert a row in table which is having instead of insert trigger on it. It's defined in my .hbm.xml file like this:
[code<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="ECM.Domain" namespace="ECM.Domain" >
<class name="Employee" table="Employee" >
<id name="Id" column="EMPLOYEE_ID" type="Int32" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="Name" column="NAME" type="String" length="100" not-null="true" />
</class>
</hibernate-mapping>
public class Employee
{
private int id;
public int Id
{
get { return id; }
set { id = value; }
}
private String name;
public String Name
{
get { return name; }
set { name = value; }
}
}
CODE:
sessionFactory = new NHibernate.Cfg.Configuration().Configure().BuildSessionFactory();
ISession dataSession;
Employee EmployeeItem = null;
try
{
dataSession = sessionFactory.OpenSession();
EmployeeItem = (Employee)dataSession.CreateCriteria(typeof(Employee))
.Add(Expression.Eq(id, Name)).UniqueResult();
if (EmployeeItem != null)
return 2;
EmployeeItem = new Employee();
EmployeeItem.Name = Name;
tx = dataSession.BeginTransaction();
dataSession.Save(EmployeeItem);
tx.Commit();
while saving it is giving DBnull cannot be changed to Int32,64
I debugged and tried while inserting query generated is like this
Select SCOPE_IDENTITY(); it returns null since a trigger is there and
the sope of query is over.
if we use @@identity it will return identity even sope of query is over.
can we generate @@identity through nhibernate.
is there any way i can get identity even trigger is there .
_________________ venkat
|