Entity Framework 6.1.1 Naming Convention for indexes

心不动则不痛 提交于 2020-01-01 11:55:26

问题


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.


回答1:


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

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


来源:https://stackoverflow.com/questions/25903791/entity-framework-6-1-1-naming-convention-for-indexes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!