ServiceStack.OrmLite: 索引的自定义命名可以用代码实现吗?

ServiceStack.OrmLite: Can custom naming of index be done in code?

(我是运行 ServiceStack OrmLite 5.1.1)

我碰巧有一些名称很长的对象,现在按设置创建 table 会创建一个名称很长的 table。当 OrmLite 尝试在一列上创建索引时,失败并显示:

Could not create table co_BookingRecurring_RecurringBookingAdministrationGroup (type tWorks.Alfa.AlfaCommons.BookingRecurring.RecurringBookingAdministrationGroup): Identifier name 'idx_co_bookingrecurring_recurringbookingadministrationgroup_deleted' is too long

所以,我希望 IndexAttribute 也包含一个构造函数,这样我就可以更改它,它会变成 idx_deleted,但是我找不到这样的构造函数或其他方法处理它。

我找到了 INamingStrategy interface and some examples,但它们似乎不处理索引名称。

有没有办法处理这个问题,以便我可以正常使用 CreateTable?

方案 A:避免用户定义的长名称:"RecurringBookingAdministrationGroup"

B 计划:(或者 OrmLite 对此有过错):不要在 table 中的任何名称中包含 table 名称("BookRecurring"?) (除了 'id')。

C 计划:找人修复 OrmLite。一种修复方法是截断长名称并附加一个固定长度的哈希值,该散列值应该是过长的名称。

计划 D:提交错误报告 bugs.mysql.com 抱怨名称限制。

计划E:研究MySQL 8.0;它可能有一些增加的限制;不知道他们是否在这里申请。

(与此同时,我将把它添加到我的长列表中,说明为什么第 3 方软件可以 'get in the way' 提供更多帮助。)

我在 this commit 中添加了对自定义索引名称的支持,这样您就可以提供自定义索引名称来代替基于约定的索引名称,例如:

public class Table
{
    [Index(Name = "idx_custom_name")]
    public string Name { get; set; }
}

此更改适用于现在 available on MyGet 的 v5.1.1。