mysqlindexingservicestackormlite-servicestack

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

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