实体框架6.1.1索引的命名约定 [英] Entity Framework 6.1.1 Naming Convention for indexes

查看:168
本文介绍了实体框架6.1.1索引的命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



但是我没有找到如何更改EF提供的默认索引名称

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

[索引]
public string说明{get;组;

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



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



我假设我需要在IndexAttributeConvention之后添加它,以便所有当前的功能都可以工作并创建IndexAnnotations,但是如果在Attribute(或Fluent构造)中留下空白,我找不到Indexes接收其初始名称的位置。 p>

提前感谢

解决方案

您是否尝试过此注释:[Index (IndexName)]
或您的示例:

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


I understand how to add conventions to the code first (with migrations) project. I have successfully managed to perform the table names and even changed GUID Id fields to non-clustered.

But I have not found how to change the default index name that EF supplies when no name is given.

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

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

I have these two requirements. The top index should be named UX_[schema]_[table]_Code, the second IX_[schema]_[table]_Description

I also have the need to support multiple column indexes where IsUnique will still be UX but the column section is a Camel Case combination of all columns (e.g. UX_[schema]_[table]_CodeDescription if the two columns above where in the same index.

I'm assuming I would need to add this after the IndexAttributeConvention so that all the current functionality will work and create the IndexAnnotations. But I can't find where the Indexes are receiving their initial name if left blank in the Attribute (or Fluent construct).

Thanks in advance.

解决方案

Have you tried this annotation: [Index("IndexName")] or for your example:

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

这篇关于实体框架6.1.1索引的命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆