Skip to content

Commit 247769d

Browse files
fixup! Support evaluation of Random.Next and NextDouble on db side
Hack the test for dodging a Firebird limitation combined with a wicked driver hack attempting to work around this limitation.
1 parent 6a5d457 commit 247769d

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

src/NHibernate.Test/Async/Linq/PreEvaluationTests.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,13 @@ public async Task CanQueryByRandomIntAsync()
265265
using (var spy = new SqlLogSpy())
266266
{
267267
var random = new Random();
268-
var x = await (db.Orders.CountAsync(o => o.OrderId - idMin - 1 < random.Next()));
268+
// Dodge a Firebird driver limitation by putting the constants before the order id.
269+
// This driver cast parameters to their types in some cases for avoiding Firebird complaining of not
270+
// knowing the type of the condition. For some reasons the driver considers the casting should not be
271+
// done next to the conditional operator. Having the cast only on one side is enough for avoiding
272+
// Firebird complain, so moving the constants on the left side have been put before the order id, in
273+
// order for these constants to be casted by the driver.
274+
var x = await (db.Orders.CountAsync(o => -idMin - 1 + o.OrderId < random.Next()));
269275

270276
Assert.That(x, Is.GreaterThan(0));
271277
// Next requires support of both floor and rand
@@ -309,7 +315,13 @@ public async Task CanQueryByRandomIntWithMaxAsync()
309315
using (var spy = new SqlLogSpy())
310316
{
311317
var random = new Random();
312-
var x = await (db.Orders.CountAsync(o => o.OrderId - idMin < random.Next(10)));
318+
// Dodge a Firebird driver limitation by putting the constants before the order id.
319+
// This driver cast parameters to their types in some cases for avoiding Firebird complaining of not
320+
// knowing the type of the condition. For some reasons the driver considers the casting should not be
321+
// done next to the conditional operator. Having the cast only on one side is enough for avoiding
322+
// Firebird complain, so moving the constants on the left side have been put before the order id, in
323+
// order for these constants to be casted by the driver.
324+
var x = await (db.Orders.CountAsync(o => -idMin + o.OrderId < random.Next(10)));
313325

314326
Assert.That(x, Is.GreaterThan(0).And.LessThan(10));
315327
// Next requires support of both floor and rand
@@ -353,7 +365,13 @@ public async Task CanQueryByRandomIntWithMinMaxAsync()
353365
using (var spy = new SqlLogSpy())
354366
{
355367
var random = new Random();
356-
var x = await (db.Orders.CountAsync(o => o.OrderId - idMin < random.Next(1, 11)));
368+
// Dodge a Firebird driver limitation by putting the constants before the order id.
369+
// This driver cast parameters to their types in some cases for avoiding Firebird complaining of not
370+
// knowing the type of the condition. For some reasons the driver considers the casting should not be
371+
// done next to the conditional operator. Having the cast only on one side is enough for avoiding
372+
// Firebird complain, so moving the constants on the left side have been put before the order id, in
373+
// order for these constants to be casted by the driver.
374+
var x = await (db.Orders.CountAsync(o => -idMin + o.OrderId< random.Next(1, 11)));
357375

358376
Assert.That(x, Is.GreaterThan(0).And.LessThan(10));
359377
// Next requires support of both floor and rand

src/NHibernate.Test/Linq/PreEvaluationTests.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,13 @@ public void CanQueryByRandomInt()
253253
using (var spy = new SqlLogSpy())
254254
{
255255
var random = new Random();
256-
var x = db.Orders.Count(o => o.OrderId - idMin - 1 < random.Next());
256+
// Dodge a Firebird driver limitation by putting the constants before the order id.
257+
// This driver cast parameters to their types in some cases for avoiding Firebird complaining of not
258+
// knowing the type of the condition. For some reasons the driver considers the casting should not be
259+
// done next to the conditional operator. Having the cast only on one side is enough for avoiding
260+
// Firebird complain, so moving the constants on the left side have been put before the order id, in
261+
// order for these constants to be casted by the driver.
262+
var x = db.Orders.Count(o => -idMin - 1 + o.OrderId < random.Next());
257263

258264
Assert.That(x, Is.GreaterThan(0));
259265
// Next requires support of both floor and rand
@@ -297,7 +303,13 @@ public void CanQueryByRandomIntWithMax()
297303
using (var spy = new SqlLogSpy())
298304
{
299305
var random = new Random();
300-
var x = db.Orders.Count(o => o.OrderId - idMin < random.Next(10));
306+
// Dodge a Firebird driver limitation by putting the constants before the order id.
307+
// This driver cast parameters to their types in some cases for avoiding Firebird complaining of not
308+
// knowing the type of the condition. For some reasons the driver considers the casting should not be
309+
// done next to the conditional operator. Having the cast only on one side is enough for avoiding
310+
// Firebird complain, so moving the constants on the left side have been put before the order id, in
311+
// order for these constants to be casted by the driver.
312+
var x = db.Orders.Count(o => -idMin + o.OrderId < random.Next(10));
301313

302314
Assert.That(x, Is.GreaterThan(0).And.LessThan(10));
303315
// Next requires support of both floor and rand
@@ -341,7 +353,13 @@ public void CanQueryByRandomIntWithMinMax()
341353
using (var spy = new SqlLogSpy())
342354
{
343355
var random = new Random();
344-
var x = db.Orders.Count(o => o.OrderId - idMin < random.Next(1, 11));
356+
// Dodge a Firebird driver limitation by putting the constants before the order id.
357+
// This driver cast parameters to their types in some cases for avoiding Firebird complaining of not
358+
// knowing the type of the condition. For some reasons the driver considers the casting should not be
359+
// done next to the conditional operator. Having the cast only on one side is enough for avoiding
360+
// Firebird complain, so moving the constants on the left side have been put before the order id, in
361+
// order for these constants to be casted by the driver.
362+
var x = db.Orders.Count(o => -idMin + o.OrderId< random.Next(1, 11));
345363

346364
Assert.That(x, Is.GreaterThan(0).And.LessThan(10));
347365
// Next requires support of both floor and rand

0 commit comments

Comments
 (0)