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

Commit 106b39f

Browse files
committed
handle AsNoTrackingWithIdentityResolution (#352)
(cherry picked from commit bfeb866) (cherry picked from commit 177d647) # Conflicts: # Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs
1 parent 24f2361 commit 106b39f

File tree

4 files changed

+61
-20
lines changed

4 files changed

+61
-20
lines changed

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ public virtual MappingSchema GetMappingSchema(
554554
MemberHelper.MethodOfGeneric<IIncludableQueryable<object, IEnumerable<object>>>(q => q.ThenInclude<object, object, object>(null!));
555555

556556
static readonly MethodInfo AsNoTrackingMethodInfo = MemberHelper.MethodOfGeneric<IQueryable<object>>(q => q.AsNoTracking());
557+
static readonly MethodInfo AsNoTrackingWithIdentityResolutionMethodInfo = MemberHelper.MethodOfGeneric<IQueryable<object>>(q => q.AsNoTrackingWithIdentityResolution());
557558

558559
static readonly MethodInfo EFProperty = MemberHelper.MethodOfGeneric(() => EF.Property<object>(1, ""));
559560

@@ -809,7 +810,8 @@ TransformInfo LocalTransform(Expression e)
809810
methodCall.Arguments[0], Expression.NewArrayInit(typeof(Type)));
810811
return new TransformInfo(newMethod, false, true);
811812
}
812-
else if (generic == AsNoTrackingMethodInfo)
813+
else if (generic == AsNoTrackingMethodInfo
814+
|| generic == AsNoTrackingWithIdentityResolutionMethodInfo)
813815
{
814816
isTunnel = true;
815817
tracking = false;
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
namespace LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping;
2-
3-
public class WithInheritance
1+
namespace LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping
42
{
5-
public int Id { get; set; }
6-
public string Discriminator { get; set; } = null!;
7-
}
3+
public class WithInheritance
4+
{
5+
public int Id { get; set; }
6+
public string Discriminator { get; set; } = null!;
7+
}
88

9-
public class WithInheritanceA : WithInheritance
10-
{
11-
12-
}
9+
public class WithInheritanceA : WithInheritance
10+
{
1311

14-
public class WithInheritanceA1 : WithInheritanceA
15-
{
16-
17-
}
12+
}
1813

19-
public class WithInheritanceA2 : WithInheritanceA
20-
{
21-
14+
public class WithInheritanceA1 : WithInheritanceA
15+
{
16+
17+
}
18+
19+
public class WithInheritanceA2 : WithInheritanceA
20+
{
21+
22+
}
2223
}

Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/IssueTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,13 @@ public void Issue321Test()
8989

9090
var _ = ctx.Patents.AsSqlServer().ToLinqToDB().ToArray();
9191
}
92+
93+
[Test(Description = "https://github.com/linq2db/linq2db.EntityFrameworkCore/issues/345")]
94+
public void AsNoTrackingWithIdentityResolutionHandling()
95+
{
96+
using var ctx = CreateContext();
97+
98+
_ = ctx.Patents.AsNoTrackingWithIdentityResolution().ToLinqToDB().ToArray();
99+
}
92100
}
93101
}

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private NorthwindContext CreateContext(bool enableFilter)
8686
if (ctx.Database.EnsureCreated())
8787
{
8888
NorthwindData.Seed(ctx);
89-
}
89+
}
9090
return ctx;
9191
}
9292

@@ -882,6 +882,37 @@ public void TestTagWith([Values(true, false)] bool enableFilter)
882882
}
883883
}
884884

885+
886+
[Test]
887+
public void TestTemporalTables([Values(true, false)] bool enableFilter)
888+
{
889+
using (var ctx = CreateContext(enableFilter))
890+
{
891+
var query1 = ctx.Products.TemporalAsOf(DateTime.UtcNow);
892+
var query2 = ctx.Products.TemporalFromTo(DateTime.UtcNow.AddDays(-1), DateTime.UtcNow);
893+
var query3 = ctx.Products.TemporalAll();
894+
var query4 = ctx.Products.TemporalBetween(DateTime.UtcNow.AddDays(-1), DateTime.UtcNow);
895+
var query5 = ctx.Products.TemporalContainedIn(DateTime.UtcNow.AddDays(-1), DateTime.UtcNow);
896+
897+
var result1 = query1.ToLinqToDB().ToArray();
898+
var result2 = query2.ToLinqToDB().ToArray();
899+
var result3 = query3.ToLinqToDB().ToArray();
900+
var result4 = query4.ToLinqToDB().ToArray();
901+
var result5 = query5.ToLinqToDB().ToArray();
902+
903+
var allQuery =
904+
from p in ctx.Products.ToLinqToDB()
905+
from q1 in ctx.Products.TemporalAsOf(DateTime.UtcNow).Where(q => q.ProductId == p.ProductId).DefaultIfEmpty()
906+
from q2 in ctx.Products.TemporalFromTo(DateTime.UtcNow.AddDays(-1), DateTime.UtcNow).Where(q => q.ProductId == p.ProductId).DefaultIfEmpty()
907+
from q3 in ctx.Products.TemporalAll().Where(q => q.ProductId == p.ProductId).DefaultIfEmpty()
908+
from q4 in ctx.Products.TemporalBetween(DateTime.UtcNow.AddDays(-1), DateTime.UtcNow).Where(q => q.ProductId == p.ProductId).DefaultIfEmpty()
909+
from q5 in ctx.Products.TemporalContainedIn(DateTime.UtcNow.AddDays(-1), DateTime.UtcNow).Where(q => q.ProductId == p.ProductId).DefaultIfEmpty()
910+
select p;
911+
912+
var result = allQuery.ToArray();
913+
}
914+
}
915+
885916
[Test]
886917
public void TestInheritanceBulkCopy([Values] BulkCopyType copyType)
887918
{
@@ -921,6 +952,5 @@ public void TestInheritanceShadowBulkCopy([Values] BulkCopyType copyType)
921952
}
922953
}
923954
*/
924-
925955
}
926956
}

0 commit comments

Comments
 (0)