Skip to content

Commit ee5825a

Browse files
PanyushkinDPanyushkinD
authored andcommitted
Fix AsExpandable
1 parent 0f70072 commit ee5825a

File tree

6 files changed

+65
-7
lines changed

6 files changed

+65
-7
lines changed

EFCore.CommonTools.Tests/AssertExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using System.Linq.Expressions;
34
using Microsoft.VisualStudio.TestTools.UnitTesting;
45

@@ -46,5 +47,14 @@ public static void MethodCallsAreMatch(this Assert assert, Expression expexted,
4647
}
4748
}
4849
}
50+
51+
public static void SequenceEqual<T>(this Assert assert, IEnumerable<T> expexted, IEnumerable<T> actual)
52+
{
53+
expexted = expexted.ToList();
54+
actual = actual.ToList();
55+
56+
Assert.AreEqual(expexted.Count(), actual.Count());
57+
Assert.IsTrue(expexted.SequenceEqual(actual));
58+
}
4959
}
5060
}

EFCore.CommonTools.Tests/Querying/ExtensionExpanderTests.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void ShouldExpandExtensions()
136136
.Where(p => p.CreatedUtc > today)
137137
.Take(5)
138138
.Count());
139-
139+
140140
Assert.AreEqual(expected.ToString(), query.ToString());
141141

142142
Assert.AreNotSame(expected.Expression, query.Expression);
@@ -176,7 +176,41 @@ public void ShouldExpandGeneric()
176176
Assert.IsNull(query.FirstOrDefault());
177177
}
178178
}
179-
179+
180+
[TestMethod]
181+
public void ShouldExpandBoundLambdas()
182+
{
183+
using (var context = CreateSqliteDbContext())
184+
{
185+
var user = new User();
186+
context.Users.Add(user);
187+
188+
var post = new Post { Title = "first", Author = user };
189+
context.Posts.Add(post);
190+
191+
context.SaveChanges();
192+
193+
var query = context.Users.AsExpandable()
194+
.SelectMany(u => context.Posts
195+
.Filter(p => p.CreatorUserId == u.Id && !p.IsDeleted));
196+
197+
var expected = context.Users.AsExpandable()
198+
.SelectMany(u => context.Posts
199+
.Where(p => p.CreatorUserId == u.Id && !p.IsDeleted));
200+
201+
Assert.AreEqual(expected.ToString(), query.ToString());
202+
203+
Assert.AreNotSame(expected.Expression, query.Expression);
204+
205+
Assert.That.MethodCallsAreMatch(expected.Expression, query.Expression);
206+
207+
var queryPosts = query.ToList();
208+
var expectedPosts = expected.ToList();
209+
210+
Assert.That.SequenceEqual(expectedPosts.Select(p => p.Id), queryPosts.Select(p => p.Id));
211+
}
212+
}
213+
180214
[TestMethod]
181215
public void ShouldExpandNestedExtensions()
182216
{

EFCore.CommonTools/EntityFrameworkCore.CommonTools.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<PackageId>EntityFrameworkCore.CommonTools</PackageId>
6-
<PackageVersion>2.0.0</PackageVersion>
6+
<PackageVersion>2.0.1</PackageVersion>
77
<Description>An extension for EntityFrameworkCore that provides Auditing, Concurrency Checks, JSON Complex Types and writing history to Transaction Log.</Description>
88
<Authors>Dmitry Panyushkin</Authors>
99
<Company />
@@ -13,7 +13,7 @@
1313
<RepositoryUrl>https://github.com/gnaeus/EntityFramework.CommonTools.git</RepositoryUrl>
1414
<RepositoryType>git</RepositoryType>
1515
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
16-
<PackageReleaseNotes>EFCore 2.0; Improve AuditableEntities API</PackageReleaseNotes>
16+
<PackageReleaseNotes>.AsExpandable() works with bound lambda arguments</PackageReleaseNotes>
1717
<Copyright>Copyright © Dmitry Panyushkin 2017</Copyright>
1818
<PackageTags>EF EFCore EntityFrameworkCore EntityFramework Entity Framework ChangeTracking Change Tracking Auditing Audit TransactionLog Transaction Log ComplexType Complex Type JSON</PackageTags>
1919
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>

EFCore.CommonTools/Expression/ExpressionExtensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ public static object GetValue(this Expression expression)
8282
}
8383
}
8484
break;
85+
86+
case ExpressionType.Quote:
87+
var quoteExpression = (UnaryExpression)expression;
88+
{
89+
return GetValue(quoteExpression.Operand);
90+
}
91+
92+
case ExpressionType.Lambda:
93+
return expression;
8594
}
8695

8796
// we can't interpret the expression but we can compile and run it

EntityFramework.CommonTools/EntityFramework.CommonTools.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>EntityFramework.CommonTools</id>
5-
<version>2.0.0</version>
5+
<version>2.0.1</version>
66
<summary>Auditing, Concurrency Checks, JSON properties and Transaction Logs for EntityFramework</summary>
77
<description>An extension for EntityFramework that provides Auditing, Concurrency Checks, storing complex types as JSON and storing history of all changes from DbContext to Transaction Log.</description>
88
<authors>Dmitry Panyushkin</authors>
@@ -11,7 +11,7 @@
1111
<licenseUrl>https://github.com/gnaeus/EntityFramework.CommonTools/blob/master/LICENSE</licenseUrl>
1212
<iconUrl>https://raw.githubusercontent.com/gnaeus/EntityFramework.CommonTools/master/icon.png</iconUrl>
1313
<requireLicenseAcceptance>false</requireLicenseAcceptance>
14-
<releaseNotes>EntityFramework 6.2; Improve AuditableEntities API</releaseNotes>
14+
<releaseNotes>.AsExpandable() works with bound lambda arguments</releaseNotes>
1515
<copyright>Copyright © Dmitry Panyushkin 2017</copyright>
1616
<tags>EF EntityFramework Entity Framework ChangeTracking Change Tracking Auditing Audit TransactionLog Transaction Log ComplexType Complex Type JSON</tags>
1717
<dependencies>

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,10 @@ All notable changes to this project will be documented in this file.
814814
The format is based on [Keep a Changelog](http://keepachangelog.com/)
815815
and this project adheres to [Semantic Versioning](http://semver.org/).
816816

817+
## [2.0.1] - 2018-03-27
818+
### Fixed
819+
- `.AsExpandable()` works with bound lambda arguments
820+
817821
## [2.0.0] - 2018-03-23
818822
### Added
819823
- EFCore 2.0 support
@@ -849,9 +853,10 @@ public interface IFullAuditableV1 : IFullTrackable,
849853
}
850854
```
851855

852-
## [1.0.0] - 2017-07-20
856+
## [1.0.0] - 2017-08-16
853857
### Added
854858
Initial project version.
855859

860+
[2.0.1]: https://github.com/gnaeus/EntityFramework.CommonTools/compare/2.0.0...2.0.1
856861
[2.0.0]: https://github.com/gnaeus/EntityFramework.CommonTools/compare/1.0.0...2.0.0
857862
[1.0.0]: https://github.com/gnaeus/EntityFramework.CommonTools/tree/1.0.0

0 commit comments

Comments
 (0)