We are currently planning on converting one of our libraries to use
NHibernate as our ORM layer (to talk to an SQL Server database) but we
are having a bit of an issue with our tables that have timestamp
columns in that there is a second roundtrip being taken to the
database in order for the timestamp column to be retrieved (which is
named Rowversion in our tables).

For example, here are the queries produced when inserting a record
into our Grading table:

exec sp_executesql N'INSERT INTO Casinolink..Grading (Name,
ManualGrading, Threshold, Colour, DateRetired) VALUES (@p0, @p1, @p2,
@p3, @p4); select SCOPE_IDENTITY()',N'@p0 nvarchar(50),@p1 bit,@p2
decimal(28,5),@p3 int,@p4
datetime',@p0=N'Performance-5-49998',@p1=0,@p2=1.00000,@p3=1,@p4=NULL

exec sp_executesql N'SELECT grading_.Rowversion as Rowversion0_ FROM
Casinolink..Grading grading_ WHERE grading_.GradingID=@p0',N'@p0
int',@p0=86558

I know it is possible using SQL to get the timestamp column as part of
the INSERT using a table variable and an OUTPUT clause and
alternatively the query for the timestamp column could be submitted at
the same time as the INSERT similar to the way the SELECT
SCOPE_IDENTITY() is being done.

Is it possible to configure NHibernate to not make that second trip to
the database?  It's going to cause us performance problems to have all
those spare roundtrips

If it helps, below is the definition we are using for our table:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
        <class name="Pgic.CasinoLink31.Common.Grading,
Pgic.CasinoLink31.Common" table="Casinolink..Grading">
                <id name="Id"  type="Int32" unsaved-value="-1"
access="nosetter.camelcase-underscore">
                        <column name="GradingID" sql-type="int" not-
null="true" unique="true" index="PK_Grading"/>
      <generator class="identity" />
                </id>
    <version name="Rowversion" generated="always" unsaved-value="null"
type="BinaryBlob">
      <column name="Rowversion" not-null="true" sql-type="timestamp"/>
    </version>
    <property name="Name" type="String">
                        <column name="Name" length="50" sql-
type="nvarchar" not-null="true" unique="true" index="UK_Name"/>
                </property>
                <property name="ManualGrading" type="Boolean">
                        <column name="ManualGrading" sql-type="bit"
not-null="true"/>
                </property>
                <property name="Threshold" type="Decimal">
                        <column name="Threshold" sql-type="money" not-
null="true"/>
                </property>
                <property name="Colour" type="Int32">
                        <column name="Colour" sql-type="int" not-
null="true"/>
                </property>
                <property name="DateRetired" type="DateTime">
                        <column name="DateRetired" sql-type="datetime"
not-null="false"/>
                </property>
        </class>
</hibernate-mapping>

Our configuration from our app.config looks like:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="DatabaseSettings">
      <section name="Default"
type="System.Configuration.IgnoreSectionHandler, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    </sectionGroup>
    <section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
  </configSections>

  <DatabaseSettings>
    <Default>
      <add key="Provider"
value="NHibernate.Connection.DriverConnectionProvider" />
      <add key="Dialect" value="NHibernate.Dialect.MsSql2000Dialect" /
>
      <add key="DriverClass"
value="NHibernate.Driver.SqlClientDriver" />
      <add key="ConnectionString" value="Data Source=localhost;Initial
Catalog=caslnk;Integrated Security=True" />
    </Default>
  </DatabaseSettings>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</
property>
      <property
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
property>
      <property
name="connection.driver_class">NHibernate.Driver.SqlClientDriver</
property>
      <property name="connection.connection_string">Data
Source=localhost;Initial Catalog=caslnk;Integrated Security=True</
property>
      <property
name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle</property>
      <property name="show_sql">false</property>
    </session-factory>
  </hibernate-configuration>
</configuration>

Thanks for any help.

-- 
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.

Reply via email to