Shane van Wyk
Shane van Wyk

Reputation: 1900

Fluent NHibernate Composite Id Length set incorrectly

Fluent NHibernate is setting my Column lengths incorrectly.

What am I doing Wrong?

public class ResourceEntryMap : ClassMap<ResourceEntry>
{
    public ResourceEntryMap ()
    {
        CompositeId ()
            .KeyProperty (x => x.Culture, set => {
            set.ColumnName ("Culture");
            set.Length (10);
            set.Access.Property ();
        })
            .KeyProperty (x => x.Name, set => {
            set.ColumnName ("Name");
            set.Length (100);
            set.Access.Property ();
        });

        Map (x => x.Type).Column ("Type").Length (20);
        Map (x => x.Value).Column ("Value").Length (4000).Not.Nullable ();
        Table ("ResourceEntry");
    }
}

When it creates the table I get this

culture character varying(255) NOT NULL,
name character varying(255) NOT NULL,
type character varying(20),
value character varying(4000) NOT NULL,
CONSTRAINT resourceentry_pkey PRIMARY KEY (culture, name)

Any Ideas?

Upvotes: 1

Views: 255

Answers (1)

Andrew Whitaker
Andrew Whitaker

Reputation: 126042

This appears to be an NHibernate bug (see here), however a Fluent NHibernate contributor mentions in that ticket that it's actually a problem with Fluent NHibernate... but it's not been fixed (see this bug)

You might be able to get around the issue somehow by using an XML mapping instead, but since Fluent just generates XML that NHibernate consumes, I'm not sure what the problem with Fluent could be (it's not clear to me from reading the two bugs I've mentioned).

The good news is that if you exclude the ColumnName option, it looks like the mapping is correct:

CompositeId ()
   .KeyProperty(x => x.Culture, set => {
        set.Length(10);
        set.Access.Property();
    })
   .KeyProperty(x => x.Name, set => {
        set.Length(100);
        set.Access.Property();
    });

Since your property names are the same as your column names, you don't need to explicitly set the column name anyway.

Upvotes: 1

Related Questions