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

Commit ecd77bf

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

File tree

3 files changed

+80
-5
lines changed

3 files changed

+80
-5
lines changed

Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs

+7-3
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

+2-1
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/ToolsTests.cs

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

0 commit comments

Comments
 (0)