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

Commit a80a7f1

Browse files
authored
Added TagWith support. (#160)
* Added TagWith support. * Fixed XML doc. * Switched to linq2db 3.4.2.
1 parent cff087d commit a80a7f1

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.1">
1818
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="5.0.2" />
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
@@ -160,5 +160,14 @@ public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToke
160160
{
161161
return QueryProvider.ExecuteAsyncEnumerable<T>(Expression, cancellationToken).Result.GetAsyncEnumerator(cancellationToken);
162162
}
163+
164+
/// <summary>
165+
/// Returns generated SQL for specific LINQ query.
166+
/// </summary>
167+
/// <returns>Generated SQL.</returns>
168+
public override string ToString()
169+
{
170+
return QueryProvider.ToString();
171+
}
163172
}
164173
}

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs

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

561+
static readonly MethodInfo TagWithMethodInfo =
562+
MemberHelper.MethodOfGeneric<IQueryable<object>>(q => q.TagWith(string.Empty));
563+
561564
static readonly MethodInfo ThenIncludeEnumerableMethodInfo =
562565
MemberHelper.MethodOfGeneric<IIncludableQueryable<object, IEnumerable<object>>>(q => q.ThenInclude<object, object, object>(null));
563566

@@ -580,6 +583,9 @@ static readonly MethodInfo
580583

581584
static readonly MethodInfo ToSql = MemberHelper.MethodOfGeneric(() => Sql.ToSql(1));
582585

586+
static readonly MethodInfo TagQueryMethodInfo =
587+
MemberHelper.MethodOfGeneric<IQueryable<object>>(q => q.TagQuery(string.Empty));
588+
583589
/// <summary>
584590
/// Removes conversions from expression.
585591
/// </summary>
@@ -871,6 +877,14 @@ TransformInfo LocalTransform(Expression e)
871877
// it is only one possible way now how to detect nested query.
872878
ignoreTracking = true;
873879
}
880+
else if (generic == TagWithMethodInfo)
881+
{
882+
var method =
883+
TagQueryMethodInfo.MakeGenericMethod(methodCall.Method.GetGenericArguments());
884+
885+
return new TransformInfo(Expression.Call(method, methodCall.Arguments.Select(a => a.Transform(l => LocalTransform(l)))
886+
.ToArray()), false, true);
887+
}
874888

875889
if (isTunnel)
876890
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="5.0.2" />
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.1.6" />
13+
<PackageReference Include="linq2db.Tools" Version="3.4.2" />
1414
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.0" />
1515
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
1616
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />

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)