【问题标题】:Entity Framework 6.1.1 Naming Convention for indexes实体框架 6.1.1 索引的命名约定
【发布时间】:2014-11-12 06:29:02
【问题描述】:

我了解如何在代码优先(使用迁移)项目中添加约定。我已经成功地执行了表名,甚至将 GUID Id 字段更改为非集群。

但我还没有找到在没有给出名称时如何更改 EF 提供的默认索引名称。

[Index(IsUnique = true)]
public string Code { get; set; }

[Index]
public string Description { get; set; }

我有这两个要求。顶部索引应命名为UX_[schema]_[table]_Code,第二个索引应命名为IX_[schema]_[table]_Description

我还需要支持多列索引,其中 IsUnique 仍将是 UX,但列部分是所有列的驼峰式组合(例如 UX_[schema]_[table]_CodeDescription,如果上面的两列在同一个索引中。

我假设我需要在 IndexAttributeConvention 之后添加它,以便所有当前功能都可以工作并创建 IndexAnnotations。但是如果在属性(或流利的构造)中留空,我找不到索引在哪里接收它们的初始名称。

提前致谢。

【问题讨论】:

    标签: entity-framework ef-code-first naming-conventions entity-framework-6.1


    【解决方案1】:

    你试过这个注解吗:[Index("IndexName")] 或以您为例:

    [Index("IndexName", IsUnique = true)]
    public string Code { get; set; }
    

    【讨论】:

    • 是的,这就是我们目前解决问题的方式。但它允许我们的开发人员创建他们想要的任何名称,而不是遵循我们现有的标准。我的问题是如何添加一个约定来命名索引。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-12
    • 1970-01-01
    • 2012-04-06
    • 1970-01-01
    相关资源
    最近更新 更多