Fluent NHibernate

The current version of Fluent NHibernate (r479) doesn’t support Sql-insert, sql-update, sql-delete.

FN can do mixed configuration, as example:

Fluently.Configure()
  .Database(configurer)
  .Mappings(m =>
  {
    m.FluentMappings.AddFromAssemblyOf<UserCreator>();
    m.HbmMappings.AddFromAssemblyOf<UserCreator>(); // loads the embedded
resources
  })
  .ExposeConfiguration(BuildSchema)
  .BuildSessionFactory();

But I can’t use this patten to partly mapping properties on the same entity using FN, and use classic hbm to implement SP.

I must work on a horrible legacy db.

Advertisements

8 thoughts on “Fluent NHibernate

  1. Frank, I believe you can still do this. I just pulled up some old code, and moved it into a new project that is using the Fluent NHibernate trunk. It compiles but I have no way to test it right now, but here is the basics:

    1. Create class StoredProcedurePart code below:

    public class StoredProcedurePart : ClasslikeMapBase, IMappingPart
    {
    private readonly string _innerText;
    private readonly string _element;
    private readonly Cache attributes = new Cache();

    public StoredProcedurePart(string element, string innerText)
    {
    _element = element;
    _innerText = innerText;
    }

    public void SetAttribute(string name, string value)
    {
    attributes.Store(name, value);
    }

    public void SetAttributes(Attributes atts)
    {
    foreach (var key in atts.Keys)
    {
    SetAttribute(key, atts[key]);
    }
    }

    public void Write(XmlElement classElement, IMappingVisitor visitor)
    {
    XmlElement subclassElement = classElement.AddElement(_element);
    subclassElement.InnerText = _innerText;

    writeTheParts(subclassElement, visitor);
    }

    public int Level
    {
    get { return 1; }
    }

    public PartPosition Position
    {
    get { return PartPosition.Last; }
    }
    }

    Then in your mapping class for your entity you can do this:

    //18 variables
    var updatesproc = new StoredProcedurePart(“sql-update”, “exec UpdateCustomer ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?”);
    AddPart(updatesproc);

    //18 variables
    var insertsproc = new StoredProcedurePart(“sql-insert”, “exec InsertCustomer ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?”);
    AddPart(insertsproc);

    Hope this helps.

  2. Pingback: Create your own Parts to merge Stored Procedure into Fluent NHibernate mappings « maonet technotes

  3. Any idea where the interface IMappingPart or IMappingVisitor is now ( even with latest source from svn it’s not there )

    Also the AddPart(insertsproc); method no longer appears to be part of the base ClassMap class.

    Any more ideas?

  4. I’ll check tomorrow what exact rev I’m using, but i’ve noticed the code has been branched
    there is a trunk.old branch which has the files for the missing interfaces, but even there the project file doesn’t include them.

    I have a feeling a lot has changed , if so I’m feeling kinda bummed

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s