From e4770f4f04185496e16f9946b976eeed96330855 Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Mon, 15 Jan 2024 05:01:43 +0800 Subject: [PATCH] There is no function to create a new guid in MS Access. Translate Guid.NewGuid client side while generating the SQL --- .../Internal/JetNewGuidTranslator.cs | 5 ++++- .../NorthwindFunctionsQueryJetTest.Functions.cs | 13 ++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetNewGuidTranslator.cs b/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetNewGuidTranslator.cs index 1510d5d..33823a2 100644 --- a/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetNewGuidTranslator.cs +++ b/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetNewGuidTranslator.cs @@ -24,13 +24,16 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal public SqlExpression? Translate(SqlExpression? instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { - return _methodInfo.Equals(method) + /*(return _methodInfo.Equals(method) ? _sqlExpressionFactory.Function( "NEWGUID", Array.Empty(), false, new[] { false }, method.ReturnType) + : null;*/ + return _methodInfo.Equals(method) + ? _sqlExpressionFactory.Constant(Guid.NewGuid(), method.ReturnType) : null; } } diff --git a/test/EFCore.Jet.FunctionalTests/Query/NorthwindFunctionsQueryJetTest.Functions.cs b/test/EFCore.Jet.FunctionalTests/Query/NorthwindFunctionsQueryJetTest.Functions.cs index 5d5e737..56cea6c 100644 --- a/test/EFCore.Jet.FunctionalTests/Query/NorthwindFunctionsQueryJetTest.Functions.cs +++ b/test/EFCore.Jet.FunctionalTests/Query/NorthwindFunctionsQueryJetTest.Functions.cs @@ -1502,11 +1502,14 @@ WHERE `o`.`OrderID` = 11077 AND (`o`.`Discount` * (3.1415927 / 180)) > 0 public override async Task Where_guid_newguid(bool isAsync) { await base.Where_guid_newguid(isAsync); - - AssertSql( - $@"SELECT `o`.`OrderID`, `o`.`ProductID`, `o`.`Discount`, `o`.`Quantity`, `o`.`UnitPrice` -FROM `Order Details` AS `o` -WHERE (GenGUID() <> '00000000-0000-0000-0000-000000000000') OR GenGUID() IS NULL"); + + //Don't validate SQL. GUID changes on each execution. + /*AssertSql( + """ +SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region` +FROM `Customers` AS `c` +WHERE '{638fa0fe-7a53-418d-958e-431093428c62}' <> '{00000000-0000-0000-0000-000000000000}' +""");*/ } public override async Task Where_string_to_upper(bool isAsync)