Skip to content

Commit 1c6dd63

Browse files
committed
Prefix index name with name of containing table to ensure uniqueness.
1 parent cbcb9b1 commit 1c6dd63

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

SQLite.CodeFirst.Console/Entity/Player.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class Player : IEntity
88
{
99
public int Id { get; set; }
1010

11-
[Index] // Automatically named 'IX_FirstName'
11+
[Index] // Automatically named 'IX_TeamPlayer_FirstName'
1212
[MaxLength(50)]
1313
public string FirstName { get; set; }
1414

SQLite.CodeFirst/Builder/CreateIndexStatementBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Data.Entity.Core.Metadata.Edm;
55
using System.Data.Entity.Infrastructure.Annotations;
66
using System.Linq;
7+
using SQLite.CodeFirst.Extensions;
78
using SQLite.CodeFirst.Statement;
89

910
namespace SQLite.CodeFirst.Builder
@@ -54,9 +55,9 @@ public CreateIndexStatementCollection BuildStatement()
5455
return new CreateIndexStatementCollection(createIndexStatments.Values);
5556
}
5657

57-
private static string GetIndexName(IndexAttribute index, EdmProperty property)
58+
private string GetIndexName(IndexAttribute index, EdmProperty property)
5859
{
59-
return index.Name ?? "IX_" + property.Name;
60+
return index.Name ?? string.Format("IX_{0}_{1}", entitySet.ElementType.GetTableName(), property.Name);
6061
}
6162
}
6263
}

0 commit comments

Comments
 (0)