0

I'm attempting to configure Fluent NHibernate with Automapping for MySQL and I've run into a problem. I've googled quite a bit and tried many different things, but haven't found a solution yet.

Anyway, here's my NHibernate configuration

return 
    Fluently.Configure()
        .Database(
            MySQLConfiguration.Standard.ConnectionString(cs => cs.FromConnectionStringWithKey("Db"))
                    .Dialect<NHibernate.Dialect.MySQL5Dialect>()
                    .ShowSql()
                )
            .Mappings(
                x =>
                x.AutoMappings
                    .Add(
                        FluentNHibernate.Automapping.AutoMap.AssemblyOf<CoreRegistry>()
                        .Where (t => t.IsDefined(typeof(AutoMap), false))
                        .Conventions.Setup (c => {
                            c.Add<NullConvention>();
                            c.Add<PrimaryKeyConvention> ();
                            c.Add<TableNameConvention> ();
                        })
                    )
            ).BuildSessionFactory();

Here's my model:

[AutoMap]
public class MyNewTable
{
    public virtual int Id {get; set;}

    public virtual string Column1 {get; set;}
    [Null]
    public virtual string Column2 {get; set;}
}

Here's my code attempting to insert the record:

using (var session = sf.OpenSession())
using (var tx = session.BeginTransaction()) {
    var myReallyTable = new MyNewTable
    {
        Column2 = null,
        Column1 = "ghrtehrthrtete"
    };

    session.Save (myReallyTable);

    tx.Commit ();
}

Lastly, here is the sql that it is actually generating:

INSERT INTO myproject.Core.MyNewTable, myproject.Core, Version=1.0.4911.33346, Culture=neutral, PublicKeyToken=null (Column1, Column2) VALUES (?, ?)

For some reason it is injecting my project's assembly name before my table name and also appending the assembly version and stuff after it. I've tried setting the default schema to my database name. I tried switching the dialect to MySQLDialect, but that didn't work either.

If anyone's got any light to shine on this I'd be very grateful.

Thanks

1 Answer 1

1

Well I get to come back and show what a jackass I am.

I had a table name convention that was using instance.Name instead of instance.EntityType.Name. Oh well, at least this post will be here if anyone wants to know how to AutoMap with MySQL. :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.