fluent-nhibernate icon indicating copy to clipboard operation
fluent-nhibernate copied to clipboard

Allow specifying `length` for `<index>` element

Open jtrbalic opened this issue 9 years ago • 4 comments

I have created auto mapping which maps Dictionary into table like this:

public class PostOverrides : IAutoMappingOverride<Post>
{
    public void Override(AutoMapping<Post> mapping)
    {   
        mapping.HasMany(x => x.Properties).AsMap<string>(
            index => index.Column("PropertyKey").Type<string>(),
            element => element.Column("PropertyValue").Type<string>().Length(5000)
        ).Table("PostProperties").Cascade.All();
    }
}

Which results in table PostProperties with columns:

PostProperties => int(11)
PropertyKey => VARCHAR(255)
PropertyValue => Text

The issue is that this mapping by default creates Index column as VARCHAR(255). But it fails to create the table entirely for databases which use utf8mb4 encoding, because the maximum VARCHAR size on an index column is 191 with utf8mb4 encoding (the recommended encoding).

This should be able to be resolved by adding a Length property to IndexPart and using it like ElementPart does.

jtrbalic avatar Dec 06 '16 09:12 jtrbalic

@carpics I see. what do you recommend we do in that scenario? we can't detect encoding of a database in Fluent - that's NHibernate work I believe

chester89 avatar Jan 10 '17 09:01 chester89

@chester89 Yes, I know it's not possible to detect encoding of a database in Fluent. I already suggested above that solution would be to add Length property to IndexPart, the same as ElementPart has so we can in Automapping set length for this column to 191 in this case.

jtrbalic avatar Jan 10 '17 10:01 jtrbalic

@carpics you want to handle that on the mapping side, understood. let me look into whether that's easy to add

chester89 avatar Jan 10 '17 10:01 chester89

@chester89

Yes, that would be great if it's possible.

jtrbalic avatar Jan 10 '17 11:01 jtrbalic