Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit ea431c3

Browse files
committed
fix regression/merge
(cherry picked from commit 806d6bf) # Conflicts: # Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs (cherry picked from commit ecd77bf) (cherry picked from commit f0e1520)
1 parent 4d990e8 commit ea431c3

File tree

4 files changed

+80
-5
lines changed

4 files changed

+80
-5
lines changed

Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,14 @@ static IEnumerable<InheritanceMappingAttribute> GetMappingAttributesRecursive(IE
144144

145145
List<InheritanceMappingAttribute> ProcessEntityType(IEntityType et)
146146
{
147-
mappings.Add(new()
147+
if (!et.ClrType.IsAbstract)
148148
{
149-
Type = et.ClrType, Code = entityType.GetDiscriminatorValue()
150-
});
149+
mappings.Add(new()
150+
{
151+
Type = et.ClrType,
152+
Code = entityType.GetDiscriminatorValue()
153+
});
154+
}
151155

152156
if (et.BaseType == null)
153157
return mappings;

Tests/LinqToDB.EntityFrameworkCore.BaseTests/ForMappingTestsBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,14 @@ public virtual async Task TestInheritance()
168168
using var context = CreateContext();
169169
using var connection = context.CreateLinqToDBConnection();
170170

171+
context.WithInheritance.AddRange(new List<WithInheritanceA>() { new() { } });
171172
context.WithInheritance.AddRange(new List<WithInheritanceA1>() { new() { }, new() { } });
172173
context.WithInheritance.AddRange(new List<WithInheritanceA2>() { new() { }, new() { } });
173174
await context.SaveChangesAsync();
174175

175176
var result = context.GetTable<WithInheritanceA>().ToList();
176177

177-
result.OfType<WithInheritance>().Should().HaveCount(4);
178+
result.OfType<WithInheritance>().Should().HaveCount(5);
178179
result.OfType<WithInheritanceA1>().Should().HaveCount(2);
179180
result.OfType<WithInheritanceA2>().Should().HaveCount(2);
180181
}

Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/Settings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public static class Settings
77
public static readonly string JsonConvertConnectionString = "Server=.;Database=JsonConvertContext;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
88
public static readonly string NorthwindConnectionString = "Server=.;Database=NorthwindEFCore;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
99
public static readonly string ConverterConnectionString = "Server=.;Database=ConverterTests;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
10+
public static readonly string InheritanceConnectionString = "Server=.;Database=InheritanceEFCore;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
1011
}
1112
}

Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using LinqToDB.Data;
66
using LinqToDB.EntityFrameworkCore.BaseTests;
77
using LinqToDB.EntityFrameworkCore.BaseTests.Models.Northwind;
8+
using LinqToDB.EntityFrameworkCore.SqlServer.Tests.Models.Inheritance;
89
using LinqToDB.EntityFrameworkCore.SqlServer.Tests.Models.Northwind;
910
using LinqToDB.Expressions;
1011
using LinqToDB.Mapping;
@@ -72,7 +73,7 @@ private NorthwindContext CreateContext(bool enableFilter)
7273
if (ctx.Database.EnsureCreated())
7374
{
7475
NorthwindData.Seed(ctx);
75-
}
76+
}
7677
return ctx;
7778
}
7879

@@ -866,5 +867,73 @@ from q5 in ctx.Products.TemporalContainedIn(DateTime.UtcNow.AddDays(-1), DateTim
866867
}
867868
}
868869

870+
static DbContextOptions CreateInheritanceOptions()
871+
{
872+
var optionsBuilder = new DbContextOptionsBuilder<InheritanceContext>();
873+
874+
optionsBuilder.UseSqlServer(Settings.InheritanceConnectionString);
875+
optionsBuilder.UseLoggerFactory(TestUtils.LoggerFactory);
876+
optionsBuilder.EnableSensitiveDataLogging();
877+
878+
return optionsBuilder.Options;
879+
}
880+
881+
private DbContextOptions? _inheritanceOptions;
882+
883+
private InheritanceContext CreateInheritanceContext()
884+
{
885+
var recreate = _inheritanceOptions == null;
886+
887+
_inheritanceOptions ??= CreateInheritanceOptions();
888+
889+
var ctx = new InheritanceContext(_inheritanceOptions);
890+
if (recreate)
891+
{
892+
ctx.Database.EnsureDeleted();
893+
ctx.Database.EnsureCreated();
894+
}
895+
896+
return ctx;
897+
}
898+
899+
[Test]
900+
public void TestInheritanceBulkCopy([Values] BulkCopyType copyType)
901+
{
902+
using (var ctx = CreateInheritanceContext())
903+
{
904+
var data = new BlogBase[] { new Blog() { Url = "BlogUrl" }, new RssBlog() { Url = "RssUrl" } };
905+
906+
ctx.BulkCopy(new BulkCopyOptions(){ BulkCopyType = BulkCopyType.RowByRow }, data);
907+
908+
var items = ctx.Blogs.ToArray();
909+
910+
items[0].Should().BeOfType<Blog>();
911+
((Blog)items[0]).Url.Should().Be("BlogUrl");
912+
913+
items[1].Should().BeOfType<RssBlog>();
914+
((RssBlog)items[1]).Url.Should().Be("RssUrl");
915+
}
916+
}
917+
918+
/*
919+
[Test]
920+
public void TestInheritanceShadowBulkCopy([Values] BulkCopyType copyType)
921+
{
922+
using (var ctx = CreateInheritanceContext())
923+
{
924+
var data = new ShadowBlogBase[] { new ShadowBlog() { Url = "BlogUrl" }, new ShadowRssBlog() { Url = "RssUrl" } };
925+
926+
ctx.BulkCopy(new BulkCopyOptions(){ BulkCopyType = BulkCopyType.RowByRow }, data);
927+
928+
var items = ctx.ShadowBlogs.ToArray();
929+
930+
items[0].Should().BeOfType<ShadowBlog>();
931+
((ShadowBlog)items[0]).Url.Should().Be("BlogUrl");
932+
933+
items[1].Should().BeOfType<ShadowRssBlog>();
934+
((ShadowRssBlog)items[1]).Url.Should().Be("RssUrl");
935+
}
936+
}
937+
*/
869938
}
870939
}

0 commit comments

Comments
 (0)