I have a User class that is persisted to a User table in the
database.  I would like to use a stored procedure for insertions,
since there is some complex logic that happens in the database.
Since the parameters required by the stored procedure are nowhere
close to the properties of the User class, I am not quite sure how
create the nhibernate mappings.

My first inclination is to create a new class called UserCreator with
parameters that map to the stored procedure one to one.  Then create a
classmap that creates the mappings for the properties.  Then, for the
stored procedure part, create a UserCreator.hbm.xml file to add the
<sql-insert> element that will call the stored procedure:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Data"
    namespace="Data">
        <class name="NHibernate.Maps.UserCreator,
InterClick.Trafficking.Admin.Data">
                <sql-insert>
                        EXEC CreateUser @Name = ?, @Pw= ?, @RoleId tinyint = 0, 
@FirstName
= ?, @LastName = ?, @Phone = ?, @Email = ?
                </sql-insert>
        </class>
</hibernate-mapping>


The problem is that inserts don't seem to be using the sql-insert
override.  It tried to use the standard generated sql and errors with
"System.Data.SqlClient.SqlException: Invalid object name
'UserCreator'"  The UserCreator.hbm.xml Build Action is set to
EmbeddedResource, and is in the same assembly that is used in the
SessionFactory configuration:

Fluently.Configure()
                                .Database(configurer)
                                .Mappings(m => m.FluentMappings
                                        .AddFromAssemblyOf<UserCreator>()
                                .ExposeConfiguration(BuildSchema)
                                .BuildSessionFactory();

I'm wondering, is this the best way to handle stored procedures that
don't directly map to a class in your domain?  Secondly, if this is
the right way, what am I doing wrong that the xml file is not being
picked up by fluent nhibernate?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" 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/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to