Today we have received a question in our dev-list about a sort
of improvement regarding generated values.
>From Trevor:
>From my view, I should be able to do something like this in NHibernate
(pseudo mapping using Fluent Nhibernate for brevity - I thought it
easier to read than XML):
class OrderMap : ClassMap<Order>
{
public OrderMap()
{
WithTable("tb_order");
Id(x => x.ID, "pk_order_id").GeneratedBy.Native();
// other mappings ...
Map(x => x.Created, "created").GenerateDate
(Behavior.OnInsert);
Map(x => x.Modified, "modified").GenerateDate
(Behavior.Always);
}
}
The answer using XML for brevity:
<class name="YourEntity">
<id type="int">
<generator class="identity"/>
</id>
<property name="Description"/>
<property name="Created" generated="always"/>
<property name="Modified" generated="always"/>
<sql-insert>INSERT INTO YourEntity (Description, Created) VALUES ( ?,
GetDate()); select SCOPE_IDENTITY()</sql-insert>
<sql-update>UPDATE YourEntity SET Description=?, Modified=GetDate() WHERE
ID=?</sql-update>
</class>
NH allow custom <loader>, custom <sql-insert>, custom <sql-update>,
custom <sql-delete>,
custom collection <loader>, custom collection <sql-insert>,
custom collection <sql-update>, custom collection <sql-delete>, custom
collection <sql-delete-all>
even using Stored-Procedure
--
Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---