|
5 | 5 | using LinqToDB.Data;
|
6 | 6 | using LinqToDB.EntityFrameworkCore.BaseTests;
|
7 | 7 | using LinqToDB.EntityFrameworkCore.BaseTests.Models.Northwind;
|
| 8 | +using LinqToDB.EntityFrameworkCore.SqlServer.Tests.Models.Inheritance; |
8 | 9 | using LinqToDB.EntityFrameworkCore.SqlServer.Tests.Models.Northwind;
|
9 | 10 | using LinqToDB.Expressions;
|
10 | 11 | using LinqToDB.Mapping;
|
@@ -72,7 +73,7 @@ private NorthwindContext CreateContext(bool enableFilter)
|
72 | 73 | if (ctx.Database.EnsureCreated())
|
73 | 74 | {
|
74 | 75 | NorthwindData.Seed(ctx);
|
75 |
| - } |
| 76 | + } |
76 | 77 | return ctx;
|
77 | 78 | }
|
78 | 79 |
|
@@ -866,5 +867,74 @@ from q5 in ctx.Products.TemporalContainedIn(DateTime.UtcNow.AddDays(-1), DateTim
|
866 | 867 | }
|
867 | 868 | }
|
868 | 869 |
|
| 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 | + */ |
869 | 939 | }
|
870 | 940 | }
|
0 commit comments