'ServiceStack.OrmLite: Can custom naming of index be done in code?
(I'm running ServiceStack OrmLite 5.1.1)
I happen to have a few objects that has a long name, and creating the table as it is setup now creates a table with a long name. When OrmLite tries to create an index on one column, it fails with:
Could not create table co_BookingRecurring_RecurringBookingAdministrationGroup (type tWorks.Alfa.AlfaCommons.BookingRecurring.RecurringBookingAdministrationGroup): Identifier name 'idx_co_bookingrecurring_recurringbookingadministrationgroup_deleted' is too long
So, I was hoping that the IndexAttribute
would also contain a constructor so I could change this and it would instead be idx_deleted
, but there is no such constructor or other way that I found to handle it.
I found the INamingStrategy interface and some examples, but they don't seem to handle index names.
Is there a way to handle this, so that I can use the CreateTable as normal?
Solution 1:[1]
I've added support for custom index names in this commit which will let you provide a custom index name to use instead of the convention-based index name, e.g:
public class Table
{
[Index(Name = "idx_custom_name")]
public string Name { get; set; }
}
This change is available from v5.1.1 that's now available on MyGet.
Solution 2:[2]
Plan A: Avoid long user-defined names: "RecurringBookingAdministrationGroup"
Plan B: (Or maybe OrmLite is at fault for this): Don't include the table name ("BookRecurring"?) in the name of anything in the table (except maybe for the 'id').
Plan C: Get someone to fix OrmLite. One approach to a fix is to truncate long names and append a fixed length hash of what should have been the overly-long name.
Plan D: File a bug report with bugs.mysql.com complaining about name limitations.
Plan E: Look into MySQL 8.0; it may have some increased limits; don't know if they apply here.
(Meanwhile, I'll add this to my long list of why 3rd party software can 'get in the way' more than help.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mythz |
Solution 2 | Rick James |