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

Commit 177d647

Browse files
committed
handle AsNoTrackingWithIdentityResolution (#352)
(cherry picked from commit bfeb866)
1 parent 8f7d7b5 commit 177d647

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
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

@@ -834,7 +835,8 @@ TransformInfo LocalTransform(Expression e)
834835
methodCall.Arguments[0], Expression.NewArrayInit(typeof(Type)));
835836
return new TransformInfo(newMethod, false, true);
836837
}
837-
else if (generic == AsNoTrackingMethodInfo)
838+
else if (generic == AsNoTrackingMethodInfo
839+
|| generic == AsNoTrackingWithIdentityResolutionMethodInfo)
838840
{
839841
isTunnel = true;
840842
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private NorthwindContext CreateContext(bool enableFilter)
7272
if (ctx.Database.EnsureCreated())
7373
{
7474
NorthwindData.Seed(ctx);
75-
}
75+
}
7676
return ctx;
7777
}
7878

0 commit comments

Comments
 (0)