EF Fluent API-复杂字段的HasIndex

时间:2018-09-10 20:45:29

标签: entity-framework indexing ef-fluent-api

我需要使用Fluent API(无DataAnnotation),并且应该创建复杂的Index(3个字段)。我尝试这样做:

ChildB

但它说:

  

表'dbo.Stop'上名称为'IX_UniqueLoad'的索引具有相同的索引   为“ LoadId”和“ LocationId”列指定的“ -1”列顺序。   确保将不同的订单值用于IndexAttribute   多列索引的每一列。

如何做到?

1 个答案:

答案 0 :(得分:1)

我找到了解决方法:

this.HasIndex(p => new { p.LoadId, p.LocationId, p.StopAction }).IsUnique();

它将生成:

CreateIndex("dbo.Stop", new[] { "LoadId", "LocationId", "StopAction" }, unique: true);