diff --git a/NorthwindCRUD/.vscode/tasks.json b/NorthwindCRUD/.vscode/tasks.json new file mode 100644 index 0000000..22282cd --- /dev/null +++ b/NorthwindCRUD/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/NorthwindCRUD.sln", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary;ForceNoAlign" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/NorthwindCRUD.sln", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary;ForceNoAlign" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/NorthwindCRUD.sln" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/NorthwindCRUD/NorthwindCRUD.sln b/NorthwindCRUD/NorthwindCRUD.sln new file mode 100644 index 0000000..ecc552e --- /dev/null +++ b/NorthwindCRUD/NorthwindCRUD.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.2.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NorthwindCRUD", "NorthwindCRUD.csproj", "{A0D23213-EEA1-7104-1A67-9ED52FDE887F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A0D23213-EEA1-7104-1A67-9ED52FDE887F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A0D23213-EEA1-7104-1A67-9ED52FDE887F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A0D23213-EEA1-7104-1A67-9ED52FDE887F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A0D23213-EEA1-7104-1A67-9ED52FDE887F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {BB60B76A-7CB6-43CA-948B-625C7A90366C} + EndGlobalSection +EndGlobal diff --git a/NorthwindCRUD/QueryBuilder/QueryExecutor.cs b/NorthwindCRUD/QueryBuilder/QueryExecutor.cs index 68057d2..ca4e253 100644 --- a/NorthwindCRUD/QueryBuilder/QueryExecutor.cs +++ b/NorthwindCRUD/QueryBuilder/QueryExecutor.cs @@ -213,7 +213,7 @@ private static Expression BuildInExpression(DataContext db, Query? query, Member private static Expression BuildInExpression(DataContext db, Query? query, MemberExpression field) { - var d = RunSubquery(db, query).Select(x => (T)ProjectField(x, query?.ReturnFields[0] ?? string.Empty)).ToArray(); + var d = RunSubquery(db, query).Select(x => (T)ProjectField(x, query?.ReturnFields[0] ?? string.Empty)).Distinct(); var m = typeof(Enumerable).GetMethods() .FirstOrDefault(method => method.Name == nameof(Enumerable.Contains) && method.GetParameters().Length == 2) ?.MakeGenericMethod(typeof(T)) ?? throw new InvalidOperationException("Missing method"); @@ -244,10 +244,10 @@ private static IEnumerable RunSubquery(DataContext db, Query? query) }; } - private static dynamic? ProjectField(dynamic? obj, string field) + private static dynamic? ProjectField(object? obj, string field) { - var property = obj?.GetType().GetProperty(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) ?? throw new InvalidOperationException($"Property '{field}' not found on type '{obj?.GetType()}'"); - return property?.GetValue(obj); + var property = obj?.GetType().GetMember(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance)?.FirstOrDefault() ?? throw new InvalidOperationException($"Property '{field}' not found on type '{obj?.GetType()}'"); + return property.GetMemberValue(obj); } private static Expression GetSearchValue(dynamic? value, Type targetType)