Skip to content

Commit eddce01

Browse files
committed
fix: ensure mapped internal entity view names are deterministic (fixes #52)
1 parent 2d35aff commit eddce01

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Version.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionEFCore3>3.9.3</VersionEFCore3>
4-
<VersionEFCore5>5.9.3</VersionEFCore5>
5-
<VersionEFCore6>6.9.3</VersionEFCore6>
6-
<VersionEFCore7>7.4.3</VersionEFCore7>
7-
<VersionEFCore8>8.1.1</VersionEFCore8>
3+
<VersionEFCore3>3.9.4</VersionEFCore3>
4+
<VersionEFCore5>5.9.4</VersionEFCore5>
5+
<VersionEFCore6>6.9.4</VersionEFCore6>
6+
<VersionEFCore7>7.4.4</VersionEFCore7>
7+
<VersionEFCore8>8.1.2</VersionEFCore8>
88
<VersionEFCore9>9.0.0</VersionEFCore9>
99
<VersionEFCore10>10.0.0</VersionEFCore10>
1010
</PropertyGroup>

src/QueryableValues.SqlServer/ModelCustomizer.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.EntityFrameworkCore.Infrastructure;
44
using Microsoft.EntityFrameworkCore.Metadata.Builders;
55
using System;
6+
using System.Linq;
67

78
namespace BlazarTech.QueryableValues
89
{
@@ -39,8 +40,22 @@ private static void SetupEntity<TEntity>(ModelBuilder modelBuilder, Action<Entit
3940
// By mapping to a fake view, we stop EF from including these entities during
4041
// SQL generation in migrations and by the Create and Drop apis in DbContext.Database.
4142
entity
42-
.ToView(Guid.NewGuid().ToString())
43+
.ToView(GetViewName(typeof(TEntity)))
4344
.HasKey(i => i.X);
45+
46+
static string GetViewName(Type type)
47+
{
48+
if (type.IsGenericType)
49+
{
50+
var typeName = type.FullName?.Substring(0, type.FullName.IndexOf('`')) ?? FallbackName(type);
51+
var args = string.Join(".", type.GetGenericArguments().Select(t => t.Name));
52+
return $"{typeName}.{args}";
53+
}
54+
55+
return type.FullName ?? FallbackName(type);
56+
57+
static string FallbackName(Type type) => $"BlazarTech.QueryableValues.{type.Name}";
58+
}
4459
});
4560
}
4661

0 commit comments

Comments
 (0)