Skip to content

Commit 6c500f8

Browse files
committed
Minor cleanup, removed property from demo entity
1 parent c60db31 commit 6c500f8

2 files changed

Lines changed: 10 additions & 17 deletions

File tree

samples/SpatialFocus.EntityFrameworkCore.Extensions.SQLiteDemo/Entities/Product.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ public Product()
2424

2525
public ProductCategory ProductCategory { get; set; }
2626

27-
public ProductCategory ProductCategorySecondField { get; set; }
28-
2927
public int ProductId { get; set; }
3028

3129
public DateTime ReleaseDate { get; set; }

src/SpatialFocus.EntityFrameworkCore.Extensions/EnumLookupExtension.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace SpatialFocus.EntityFrameworkCore.Extensions
1515

1616
public static class EnumLookupExtension
1717
{
18+
private static List<Type> ConcreteTypeSeededList { get; set; } = new List<Type>();
19+
1820
// See https://github.com/aspnet/EntityFrameworkCore/issues/12248#issuecomment-395450990
1921
public static void ConfigureEnumLookup(this ModelBuilder modelBuilder, EnumLookupOptions enumOptions)
2022
{
@@ -43,8 +45,7 @@ public static void ConfigureEnumLookup(this ModelBuilder modelBuilder, EnumLooku
4345
string tableName = enumOptions.NamingFunction(typeName);
4446
enumLookupBuilder.ToTable(tableName);
4547

46-
string keyName = enumOptions.UseNumberLookup
47-
? nameof(EnumWithNumberLookup<Enum>.Id)
48+
string keyName = enumOptions.UseNumberLookup ? nameof(EnumWithNumberLookup<Enum>.Id)
4849
: nameof(EnumWithStringLookup<Enum>.Id);
4950

5051
modelBuilder.Entity(entityType.Name).HasOne(concreteType).WithMany().HasPrincipalKey(keyName).HasForeignKey(property.Name);
@@ -63,6 +64,13 @@ public static void ConfigureEnumLookup(this ModelBuilder modelBuilder, EnumLooku
6364
modelBuilder.Entity(concreteType).Property(keyName).HasConversion(valueConverter);
6465
}
6566

67+
if (ConcreteTypeSeededList.Contains(concreteType))
68+
{
69+
continue;
70+
}
71+
72+
ConcreteTypeSeededList.Add(concreteType);
73+
6674
// TODO: Check status of https://github.com/aspnet/EntityFrameworkCore/issues/12194 before using migrations
6775
object[] data = Enum.GetValues(propertyType.GetEnumOrNullableEnumType())
6876
.OfType<object>()
@@ -84,21 +92,10 @@ public static void ConfigureEnumLookup(this ModelBuilder modelBuilder, EnumLooku
8492
})
8593
.ToArray();
8694

87-
if (!ConcreteTypeSeededList.Contains(concreteType))
88-
{
89-
ConcreteTypeSeededList.Add(concreteType);
90-
}
91-
else
92-
{
93-
continue;
94-
}
95-
9695
enumLookupBuilder.HasData(data);
9796
}
9897
}
9998

100-
private static List<Type> ConcreteTypeSeededList { get; set; } = new List<Type>();
101-
10299
private static Type GetEnumOrNullableEnumType(this Type propertyType)
103100
{
104101
if (!propertyType.IsEnumOrNullableEnumType())
@@ -109,10 +106,8 @@ private static Type GetEnumOrNullableEnumType(this Type propertyType)
109106
return propertyType.IsEnum ? propertyType : propertyType.GetGenericArguments()[0];
110107
}
111108

112-
113109
private static bool HasEnumWithAttribute(this Type propertyType)
114110
{
115-
116111
if (propertyType.GetCustomAttributes(typeof(EnumLookupAttribute), true).Any())
117112
{
118113
return true;

0 commit comments

Comments
 (0)