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

Commit 6f26fa4

Browse files
committed
Merge branch 'master' into release
2 parents 3782257 + 9c6de9f commit 6f26fa4

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
using Microsoft.EntityFrameworkCore.Metadata;
1515
using Microsoft.EntityFrameworkCore.Query;
1616
using Microsoft.EntityFrameworkCore.Query.Internal;
17+
using Microsoft.EntityFrameworkCore.Query.ExpressionVisitors;
1718
using Microsoft.Extensions.Logging;
1819

1920
using JetBrains.Annotations;
20-
using Microsoft.EntityFrameworkCore.Query.ExpressionVisitors;
2121

2222
namespace LinqToDB.EntityFrameworkCore
2323
{
@@ -388,6 +388,12 @@ public virtual IDbContextOptions GetContextOptions(DbContext context)
388388
static readonly MethodInfo AsNoTrackingMethodInfo =
389389
MemberHelper.MethodOf<IQueryable<object>>(q => q.AsNoTracking()).GetGenericMethodDefinition();
390390

391+
static readonly MethodInfo EFProperty =
392+
MemberHelper.MethodOf(() => EF.Property<object>(1, "")).GetGenericMethodDefinition();
393+
394+
private static readonly MethodInfo
395+
L2DBProperty = typeof(Sql).GetMethod(nameof(Sql.Property)).GetGenericMethodDefinition();
396+
391397
public static Expression Unwrap(Expression ex)
392398
{
393399
if (ex == null)
@@ -657,14 +663,14 @@ Expression LocalTransform(Expression e)
657663
case ExpressionType.Call:
658664
{
659665
var methodCall = (MethodCallExpression) e;
666+
var generic = methodCall.Method.IsGenericMethod ? methodCall.Method.GetGenericMethodDefinition() : methodCall.Method;
660667

661668
if (IsQueryable(methodCall))
662669
{
663670
if (methodCall.Method.IsGenericMethod)
664671
{
665672
var isTunnel = false;
666673

667-
var generic = methodCall.Method.GetGenericMethodDefinition();
668674
if (generic == IgnoreQueryFiltersMethodInfo)
669675
{
670676
ignoreQueryFilters = true;
@@ -705,6 +711,13 @@ Expression LocalTransform(Expression e)
705711
}
706712
}
707713

714+
if (generic == EFProperty)
715+
{
716+
var prop = Expression.Call(null, L2DBProperty.MakeGenericMethod(methodCall.Method.GetGenericArguments()[0]),
717+
methodCall.Arguments[0].Transform(l => LocalTransform(l)), methodCall.Arguments[1]);
718+
return prop;
719+
}
720+
708721
break;
709722
}
710723
}

Tests/LinqToDB.EntityFrameworkCore.Tests/ToolsTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ public void TestToList()
9999
}
100100
}
101101

102+
[Test]
103+
public void TestShadowProperty()
104+
{
105+
using (var ctx = CreateAdventureWorksContext())
106+
{
107+
var query = ctx.Products.Select(p => new
108+
{
109+
Color = EF.Property<string>(p, "Color")
110+
});
111+
112+
query = query.ToLinqToDB();
113+
var result = query.ToArray();
114+
}
115+
}
102116

103117
[Test]
104118
public void TestInsertFrom()

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ branches:
1010
- /dev.*/
1111

1212
environment:
13-
assemblyVersion: 1.5.0
14-
packageVersion: 1.5.0
13+
assemblyVersion: 1.5.1
14+
packageVersion: 1.5.1
1515
access_token:
1616
secure: IlfmHXRdUK6v8dX/WqieXQ==
1717

0 commit comments

Comments
 (0)