Coder Social home page Coder Social logo

Comments (8)

samcook avatar samcook commented on June 14, 2024

Also affects Any with !=

this.Model.DbObjects.Any(x => x.Foo != "hello").ShouldBe(true);
// actually returns false
SELECT
    (
        SELECT CASE
                   WHEN ((EXISTS
                          (
                              SELECT "T0"."DbObjectId",
                                     "T0"."Foo"
                              FROM "DbObject" AS "T0"
                              WHERE (("T0"."Foo") <> ('hello'))
                          )
                         )
                        ) THEN
            (1)
                   ELSE
            (0)
               END AS "EXISTS_COL"
    ) AS "value";

from shaolinq.

samcook avatar samcook commented on June 14, 2024

For reference, this is what EntityFramework 6 generates:

db.DbObjects.All(x => x.Foo == "hello"); // returns false
SELECT CASE
           WHEN (NOT EXISTS
                     (
                         SELECT 1 AS [C1]
                         FROM [dbo].[DbObjects] AS [Extent1]
                         WHERE (NOT (
                                        (N'hello' = [Extent1].[Foo])
                                        AND ([Extent1].[Foo] IS NOT NULL)
                                    )
                               )
                               OR (CASE
                                       WHEN (N'hello' = [Extent1].[Foo]) THEN
                                           CAST(1 AS BIT)
                                       WHEN (NOT (
                                                     (N'hello' = [Extent1].[Foo])
                                                     AND ([Extent1].[Foo] IS NOT NULL)
                                                 )
                                            ) THEN
                                           CAST(0 AS BIT)
                                   END IS NULL
                                  )
                     )
                ) THEN
               CAST(1 AS BIT)
           ELSE
               CAST(0 AS BIT)
       END AS [C1]
FROM
(SELECT 1 AS X) AS [SingleRowTable1];
db.DbObjects.Any(x => x.Foo != "hello"); // returns true
SELECT CASE
           WHEN (EXISTS
                 (
                     SELECT 1 AS [C1]
                     FROM [dbo].[DbObjects] AS [Extent1]
                     WHERE NOT (
                                   (N'hello' = [Extent1].[Foo])
                                   AND ([Extent1].[Foo] IS NOT NULL)
                               )
                 )
                ) THEN
               CAST(1 AS BIT)
           ELSE
               CAST(0 AS BIT)
       END AS [C1]
FROM
(SELECT 1 AS X) AS [SingleRowTable1];

from shaolinq.

tumtumtum avatar tumtumtum commented on June 14, 2024

Could you add a unit test?

from shaolinq.

samcook avatar samcook commented on June 14, 2024

Will do

from shaolinq.

samcook avatar samcook commented on June 14, 2024

Unsurprisingly, the same issue can also apply to the predicates for Where, Count, etc...

from shaolinq.

tumtumtum avatar tumtumtum commented on June 14, 2024

TLDR but is this is an issue with SQL server only or all providers?

from shaolinq.

samcook avatar samcook commented on June 14, 2024

Affects both SQL server and sqlite, haven't tried mysql or postgres

from shaolinq.

tumtumtum avatar tumtumtum commented on June 14, 2024

Yeah comparing with null is undefined so not(undefined) isn't true.

I have to have a think about where else this affects could affect the framework because LINQ semantics for NULL is different.

from shaolinq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.