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

Commit fc8feeb

Browse files
committed
Merged changes from 5.x
1 parent 871d121 commit fc8feeb

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

NuGet/linq2db.EntityFrameworkCore.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<dependencies>
1717
<group targetFramework=".NETStandard2.0">
1818
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="3.1.10" />
19-
<dependency id="linq2db" version="3.4.0" />
19+
<dependency id="linq2db" version="3.4.2" />
2020
</group>
2121
</dependencies>
2222
</metadata>

Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,14 @@ public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToke
162162
{
163163
return QueryProvider.ExecuteAsyncEnumerable<T>(Expression, cancellationToken).Result.GetAsyncEnumerator(cancellationToken);
164164
}
165+
166+
/// <summary>
167+
/// Returns generated SQL for specific LINQ query.
168+
/// </summary>
169+
/// <returns>Generated SQL.</returns>
170+
public override string ToString()
171+
{
172+
return QueryProvider.ToString();
173+
}
165174
}
166175
}

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,9 @@ public virtual MappingSchema GetMappingSchema(
563563
static readonly MethodInfo ThenIncludeMethodInfo =
564564
MemberHelper.MethodOfGeneric<IIncludableQueryable<object, object>>(q => q.ThenInclude<object, object, object>(null));
565565

566+
static readonly MethodInfo TagWithMethodInfo =
567+
MemberHelper.MethodOfGeneric<IQueryable<object>>(q => q.TagWith(string.Empty));
568+
566569
static readonly MethodInfo ThenIncludeEnumerableMethodInfo =
567570
MemberHelper.MethodOfGeneric<IIncludableQueryable<object, IEnumerable<object>>>(q => q.ThenInclude<object, object, object>(null));
568571

@@ -585,6 +588,9 @@ static readonly MethodInfo
585588

586589
static readonly MethodInfo ToSql = MemberHelper.MethodOfGeneric(() => Sql.ToSql(1));
587590

591+
static readonly MethodInfo TagQueryMethodInfo =
592+
MemberHelper.MethodOfGeneric<IQueryable<object>>(q => q.TagQuery(string.Empty));
593+
588594
/// <summary>
589595
/// Removes conversions from expression.
590596
/// </summary>
@@ -876,6 +882,14 @@ TransformInfo LocalTransform(Expression e)
876882
// it is only one possible way now how to detect nested query.
877883
ignoreTracking = true;
878884
}
885+
else if (generic == TagWithMethodInfo)
886+
{
887+
var method =
888+
TagQueryMethodInfo.MakeGenericMethod(methodCall.Method.GetGenericArguments());
889+
890+
return new TransformInfo(Expression.Call(method, methodCall.Arguments.Select(a => a.Transform(l => LocalTransform(l)))
891+
.ToArray()), false, true);
892+
}
879893

880894
if (isTunnel)
881895
return new TransformInfo(methodCall.Arguments[0], false, true);

Source/LinqToDB.EntityFrameworkCore/linq2db.EntityFrameworkCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup>
26-
<PackageReference Include="linq2db" Version="3.4.0" />
26+
<PackageReference Include="linq2db" Version="3.4.2" />
2727
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.11" />
2828
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
2929
<PrivateAssets>all</PrivateAssets>

Tests/LinqToDB.EntityFrameworkCore.BaseTests/LinqToDB.EntityFrameworkCore.BaseTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="FluentAssertions" Version="5.10.3" />
13-
<PackageReference Include="linq2db.Tools" Version="3.2.3" />
13+
<PackageReference Include="linq2db.Tools" Version="3.4.2" />
1414
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
1515
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.11" />
1616
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.11" />

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Linq;
33
using System.Threading.Tasks;
4+
using FluentAssertions;
45
using LinqToDB.Data;
56
using LinqToDB.EntityFrameworkCore.BaseTests;
67
using LinqToDB.EntityFrameworkCore.BaseTests.Models.Northwind;
@@ -816,5 +817,23 @@ RETURNS int
816817
}
817818
}
818819
}
820+
821+
[Test]
822+
public void TestTagWith([Values(true, false)] bool enableFilter)
823+
{
824+
using (var ctx = CreateContext(enableFilter))
825+
{
826+
var query = ctx.Employees.Include(e => e.ReportsToNavigation).TagWith("Tagged query");
827+
var resultEF = query.ToArray();
828+
var result = query.ToLinqToDB().ToArray();
829+
830+
var str = query.ToLinqToDB().ToString();
831+
832+
AreEqual(resultEF, result);
833+
834+
str.Should().Contain("Tagged query");
835+
}
836+
}
837+
819838
}
820839
}

0 commit comments

Comments
 (0)