Discussion:
[nhusers] How to teach NHibernate to use the returned scalar of a stored procedure used in custom sql-insert?
Zoltán Tamási
2017-08-22 09:18:17 UTC
Permalink
We have an NHibernate mapping where we have to use custom stored procedures
for inserts, updates and deletes. We have the mapping as follows.


<class name="MyNamespace.MyClass" table="[MYTABLE]">

<id name="Id" column="MYTABLE_ID"></id>

...

<sql-insert check="none">
EXECUTE SP_MY_TABLE_INSERT
@p1 = ?,
@p2 = ?
</sql-insert>

</class>

We use `check="none"` due to some legacy reasons.

The above mentioned stored procedure returns the inserted ID as a scalar.
However, when we commit the NHibernate transaction, the returned ID is not
populated into the entity instance so we still see the value 0 in the Id
property.

How could we teach NHibernate that the returned scalar should be treated as
the inserted ID?
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Michael Powell
2017-08-23 18:15:56 UTC
Permalink
Post by Zoltán Tamási
We have an NHibernate mapping where we have to use custom stored
procedures for inserts, updates and deletes. We have the mapping as follows.
ISession.Connection? ... .CreateCommand() ... And so on.

That's not necessarily an "insert/update" in the sense of SaveOrUpdate, but
you would be teaching your Repository how to handle those issues.

That's assuming your underlying Provider supports Connections, creating
Commands, etc.

BTW, works fine for me during migrations. I'm not yielding a Uuid's, per
se, but I do yield responses back. Same applies here I expect.
Post by Zoltán Tamási
<class name="MyNamespace.MyClass" table="[MYTABLE]">
<id name="Id" column="MYTABLE_ID"></id>
...
<sql-insert check="none">
EXECUTE SP_MY_TABLE_INSERT
@p1 = ?,
@p2 = ?
</sql-insert>
</class>
We use `check="none"` due to some legacy reasons.
The above mentioned stored procedure returns the inserted ID as a scalar.
However, when we commit the NHibernate transaction, the returned ID is not
populated into the entity instance so we still see the value 0 in the Id
property.
How could we teach NHibernate that the returned scalar should be treated
as the inserted ID?
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Loading...