Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying length for <index> element #363

Open
carpics opened this issue Dec 6, 2016 · 4 comments
Open

Allow specifying length for <index> element #363

carpics opened this issue Dec 6, 2016 · 4 comments

Comments

@carpics
Copy link

carpics commented Dec 6, 2016

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.

@chester89
Copy link
Collaborator

@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

@carpics
Copy link
Author

carpics commented Jan 10, 2017

@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.

@chester89
Copy link
Collaborator

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

@carpics
Copy link
Author

carpics commented Jan 10, 2017

@chester89

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

@hazzik hazzik changed the title fluent nhibernate unable to create valid mysql utf8mb4 encoded tables from Dictionary mapping Allow specifying length for <index> element Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants