Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure MaxIdentifierLength constant in EF Core 2.1?

After upgrade from EF 2.0 to 2.1 we found that new migration recreates FKs and indexes in some strange manner shrinking their names to 63 chars. Also, the MaxIdentifierLength attribute was present in the top of migration file. I made some research and did not find how to configure that length default.

like image 315
Andrii Horda Avatar asked Nov 15 '25 05:11

Andrii Horda


1 Answers

Currently there is no fluent API for that.

But it can be accessed via RelationalModelAnnotations class:

var maxIdentifierLength = modelBuilder.Model.Relational().MaxIdentifierLength;

It can also be modified:

modelBuilder.Model.Relational().MaxIdentifierLength = newValue;

but I won't recommend that. Each db provider sets by default the maximum supported identifier length (for SqlServer it's 128), hence configuring greater value will probably lead to invalid table / constraint names and runtime exceptions.

like image 105
Ivan Stoev Avatar answered Nov 17 '25 19:11

Ivan Stoev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!