diff --git a/src/GoatQuery/src/Utilities/PropertyMappingTree.cs b/src/GoatQuery/src/Utilities/PropertyMappingTree.cs index cec70a4..d456bf6 100644 --- a/src/GoatQuery/src/Utilities/PropertyMappingTree.cs +++ b/src/GoatQuery/src/Utilities/PropertyMappingTree.cs @@ -23,7 +23,30 @@ public bool TryGetProperty(string jsonPropertyName, out PropertyMappingNode node return false; } - return ((Dictionary)Properties).TryGetValue(jsonPropertyName, out node); + if (((Dictionary)Properties).TryGetValue(jsonPropertyName, out node)) + { + return true; + } + + if (jsonPropertyName.EndsWith("Id", StringComparison.OrdinalIgnoreCase) && SourceType != null) + { + var typeName = SourceType.Name; + var expectedAlias = typeName + "Id"; + if (jsonPropertyName.Equals(expectedAlias, StringComparison.OrdinalIgnoreCase)) + { + foreach (var kvp in (Dictionary)Properties) + { + if (string.Equals(kvp.Value.ActualPropertyName, "Id", StringComparison.OrdinalIgnoreCase)) + { + node = kvp.Value; + return true; + } + } + } + } + + node = null; + return false; } internal void AddProperty(string jsonPropertyName, PropertyMappingNode node) diff --git a/src/GoatQuery/tests/Filter/FilterTest.cs b/src/GoatQuery/tests/Filter/FilterTest.cs index 35f6354..d050445 100644 --- a/src/GoatQuery/tests/Filter/FilterTest.cs +++ b/src/GoatQuery/tests/Filter/FilterTest.cs @@ -102,6 +102,11 @@ public static IEnumerable Parameters() new[] { TestData.Users["Harry"] } }; + yield return new object[] { + "userid eq e4c7772b-8947-4e46-98ed-644b417d2a08 or id eq 01998fda-e310-793c-bd8d-f6a92f87b31b", + new[] { TestData.Users["Jane"], TestData.Users["Harry"] } + }; + yield return new object[] { "age lt 3", new[] { TestData.Users["John"], TestData.Users["Apple"], TestData.Users["Harry"], TestData.Users["Doe"] } diff --git a/src/GoatQuery/tests/TestData.cs b/src/GoatQuery/tests/TestData.cs index e04c1f0..86e208c 100644 --- a/src/GoatQuery/tests/TestData.cs +++ b/src/GoatQuery/tests/TestData.cs @@ -1,5 +1,15 @@ public static class TestData { + private static readonly User Manager01 = new User + { + Id = Guid.Parse("671e6bac-b6de-4cc7-b3e9-1a6ac4546b43"), + Age = 16, + Firstname = "Manager 01", + DateOfBirth = DateTime.Parse("2000-01-01 00:00:00").ToUniversalTime(), + BalanceDecimal = 2.00m, + IsEmailVerified = false, + }; + public static readonly Dictionary Users = new Dictionary { ["John"] = new User @@ -22,17 +32,11 @@ public static class TestData City = new City { Name = "Boston", Country = "USA" } } }, - Manager = new User - { - Age = 16, - Firstname = "Manager 01", - DateOfBirth = DateTime.Parse("2000-01-01 00:00:00").ToUniversalTime(), - BalanceDecimal = 2.00m, - IsEmailVerified = false - } + Manager = Manager01 }, ["Jane"] = new User { + Id = Guid.Parse("01998fda-e310-793c-bd8d-f6a92f87b31b"), Age = 9, Firstname = "Jane", DateOfBirth = DateTime.Parse("2020-05-09 15:30:00").ToUniversalTime(), @@ -72,18 +76,12 @@ public static class TestData City = new City { Name = "New York", Country = "USA" } } }, - Manager = new User - { - Age = 16, - Firstname = "Manager 01", - DateOfBirth = DateTime.Parse("2000-01-01 00:00:00").ToUniversalTime(), - BalanceDecimal = 2.00m, - IsEmailVerified = true - }, + Manager = Manager01, Tags = ["vip", "premium"] }, ["Harry"] = new User { + Id = Guid.Parse("e4c7772b-8947-4e46-98ed-644b417d2a08"), Age = 1, Firstname = "Harry", DateOfBirth = DateTime.Parse("2002-08-01").ToUniversalTime(), @@ -147,7 +145,7 @@ public static class TestData Firstname = "Manager 04", DateOfBirth = DateTime.Parse("1983-04-21 00:00:00").ToUniversalTime(), BalanceDecimal = 39.00m, - IsEmailVerified = true + IsEmailVerified = true, }, Company = new Company { @@ -170,4 +168,4 @@ public static class TestData Addresses = Array.Empty
() }, }; -} \ No newline at end of file +}