Skip to content

Commit 8eb69af

Browse files
committed
Fix subquery support
1 parent c43fab6 commit 8eb69af

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

NorthwindCRUD/.vscode/tasks.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/NorthwindCRUD.sln",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary;ForceNoAlign"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/NorthwindCRUD.sln",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary;ForceNoAlign"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"--project",
36+
"${workspaceFolder}/NorthwindCRUD.sln"
37+
],
38+
"problemMatcher": "$msCompile"
39+
}
40+
]
41+
}

NorthwindCRUD/NorthwindCRUD.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.5.2.0
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NorthwindCRUD", "NorthwindCRUD.csproj", "{A0D23213-EEA1-7104-1A67-9ED52FDE887F}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{A0D23213-EEA1-7104-1A67-9ED52FDE887F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{A0D23213-EEA1-7104-1A67-9ED52FDE887F}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{A0D23213-EEA1-7104-1A67-9ED52FDE887F}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{A0D23213-EEA1-7104-1A67-9ED52FDE887F}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {BB60B76A-7CB6-43CA-948B-625C7A90366C}
23+
EndGlobalSection
24+
EndGlobal

NorthwindCRUD/QueryBuilder/QueryExecutor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private static Expression BuildInExpression(DataContext db, Query? query, Member
213213

214214
private static Expression BuildInExpression<T>(DataContext db, Query? query, MemberExpression field)
215215
{
216-
var d = RunSubquery(db, query).Select(x => (T)ProjectField(x, query?.ReturnFields[0] ?? string.Empty)).ToArray();
216+
var d = RunSubquery(db, query).Select(x => (T)ProjectField(x, query?.ReturnFields[0] ?? string.Empty)).Distinct();
217217
var m = typeof(Enumerable).GetMethods()
218218
.FirstOrDefault(method => method.Name == nameof(Enumerable.Contains) && method.GetParameters().Length == 2)
219219
?.MakeGenericMethod(typeof(T)) ?? throw new InvalidOperationException("Missing method");
@@ -244,10 +244,10 @@ private static IEnumerable<dynamic> RunSubquery(DataContext db, Query? query)
244244
};
245245
}
246246

247-
private static dynamic? ProjectField(dynamic? obj, string field)
247+
private static dynamic? ProjectField(object? obj, string field)
248248
{
249-
var property = obj?.GetType().GetProperty(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) ?? throw new InvalidOperationException($"Property '{field}' not found on type '{obj?.GetType()}'");
250-
return property?.GetValue(obj);
249+
var property = obj?.GetType().GetMember(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance)?.FirstOrDefault() ?? throw new InvalidOperationException($"Property '{field}' not found on type '{obj?.GetType()}'");
250+
return property.GetMemberValue(obj);
251251
}
252252

253253
private static Expression GetSearchValue(dynamic? value, Type targetType)

0 commit comments

Comments
 (0)