FNH 1.3, NH 3.2 - My table name convention not used

62 views
Skip to first unread message

Trinition

unread,
Mar 4, 2013, 11:24:30 AM3/4/13
to fluent-n...@googlegroups.com
I'm trying to set a table name convention:

            var myConvention = ConventionBuilder.Class.When(
                c => c.Expect(x => x.TableName, Is.Not.Set),
                x => x.Table(string.Format("tbl{0}s", x.EntityType.Name))), // class Foo becomes tblFoos

            fluentConfiguration.Mappings(m =>
            {
                ...
                m.FluentMappings.Conventions.Add(myConvention);


So when the table name isn't already set, it will set one.

This isn't working.  Debugging, I think I've found that table name is actually already set at this point to, for example, "`Foo`", for a class named "Foo".  It's as if FluentNHibernate is trying to set a table name by default even before my conventions are consulted.

Did something change in FNH 1.3?

Trinition

unread,
Mar 5, 2013, 11:04:45 AM3/5/13
to fluent-n...@googlegroups.com
It appears that the back-ticked default names come from the various Mapping class' "GetDefaultTableName()" methods.  This change was introduced by "jagregory" back in 2011.  The comment says:

Refactored "attribute" values into multiple layers instead of just defaults and non-defaults. We've now got three layers: defaults, conventions, and user-supplied. This distinction allows us to provide sensible default values which get overwritten by conventions, and user supplied values that override conventions.

I assume that "`EntityName`" is the "sensible default", but my convention is not overwriting it as the comment suggests it should.  The "Is.Not.Set" expectation isn't matching "`TableName`".  I am adding my conventions before discovering maps in assemblies.  Is there something else I need to do for my conventions to override the sensible defaults?

Trinition

unread,
Mar 5, 2013, 11:05:15 AM3/5/13
to fluent-n...@googlegroups.com

Gleb Chermennov

unread,
Mar 5, 2013, 12:11:57 PM3/5/13
to fluent-n...@googlegroups.com
So, it's not a bug then, but a new expected behaviour?

вторник, 5 марта 2013 г., 20:05:15 UTC+4 пользователь Trinition написал:

Trinition

unread,
Mar 6, 2013, 7:30:37 AM3/6/13
to fluent-n...@googlegroups.com
No.  As I understand it, the behavior should be this:
  • If there is an explicitly set table name on a ClassMap, use that table name.
  • Else, if there is a convention, use that convention's table name.
  • Else, use a sensible default value (e.g. "`MyEntity`")
However, in practice, the logic isn't being honored in that order.  I do not have an explicit table name on my Classmap, but I do have a convention.  However, my convention is finding that there is already a table name implicitly set -- to the sensible default.  That is, when I debug and watch my convention's criteria -- Is.Not.Set -- execute, it finds there is in fact a table name set, so my convention skips setting one.  but that table name it found already set is the one from the sensible default!

Trinition

unread,
May 17, 2013, 2:41:08 PM5/17/13
to fluent-n...@googlegroups.com
I've opened an issue for this problem: https://github.com/jagregory/fluent-nhibernate/issues/223


On Monday, March 4, 2013 11:24:30 AM UTC-5, Trinition wrote:
Reply all
Reply to author
Forward
0 new messages