views:

174

answers:

2

I have the following code. In SQL Server profiler I can see the isnert statement being generated however no actual record has been inserted. I just can't figure out why this is happening!

private ISessionFactory _sessionFactory;
private Configuration _configuration;

_configuration = new Configuration();
_configuration.Configure();
_configuration.AddAssembly(typeof(Task).Assembly);
_sessionFactory = _configuration.BuildSessionFactory();

using (var s = _sessionFactory.OpenSession())
using (var t = s.BeginTransaction(IsolationLevel.RepeatableRead))
{
    var taskToSave = new Task
                         {
                             Class = "test class",
                             IsActive = true,
                             Namespace = "test namespace"
                         };

    s.FlushMode = FlushMode.Commit;
    s.Save(taskToSave);
    t.Commit();
}

My mapping file is like this:

<class name="Task" table="Task">
  <id name="Id" column="Id" unsaved-value="0" type="Int32">
    <generator class ="identity"></generator>
  </id>

  <property name="IsActive" column="IsActive" not-null="true" type="Boolean" />
  <property name="Namespace" column="Namespace" length="255" not-null="true" type="String" />
  <property name="Class" column="Class" length="255" not-null="true" type="String" />
</class>

Thank you! BTW I am using NHibernate-2.1.0.CR1.

A: 

It was because I had SchemaExport somewhere in the code without me realizing it and when the code runs SchemaExport created a new table called dbo_owner_Task and inserted into that table instaed of dbo.Task.

So becareful when using SchemaExport!!!

Jeffrey C
A: 

How were you able to find that out?

Musikero31
you can find out by taking look at your db tables
Jeffrey C