How to detect when EF Core must do some of the IQueryable operations in memory










3















I've been going through my application, and there are times where only part of the IQueryable is actually translated into a SQL query and the rest of the work is done in-memory.



I understand that there's no way for the EF team to account for every possible expression that a developer may come up with and magically translate that into a useable SQL query, but IIRC, EF would throw an exception if it was unable to translate ALL of the operations defined in an IQueryable to SQL.



Is there a way to have EF Core also throw an exception, or at the very least, raise an event when it's unable to fully translate an IQueryable into SQL?










share|improve this question

















  • 2





    See Client vs. Server Evaluation - Disabling client evaluation documentation topic - the explanation and example. I think there is nothing we can add.

    – Ivan Stoev
    Dec 6 '17 at 20:11






  • 1





    @Ivan, please write this as an answer and I will mark it correct, it's exactly what I am looking for! I suspect I didn't find it while I was searching because, for me, I don't think of app server and database server in terms of client and server, though they certainly are, so I never searched with those words.

    – Brian Ball
    Dec 6 '17 at 21:40















3















I've been going through my application, and there are times where only part of the IQueryable is actually translated into a SQL query and the rest of the work is done in-memory.



I understand that there's no way for the EF team to account for every possible expression that a developer may come up with and magically translate that into a useable SQL query, but IIRC, EF would throw an exception if it was unable to translate ALL of the operations defined in an IQueryable to SQL.



Is there a way to have EF Core also throw an exception, or at the very least, raise an event when it's unable to fully translate an IQueryable into SQL?










share|improve this question

















  • 2





    See Client vs. Server Evaluation - Disabling client evaluation documentation topic - the explanation and example. I think there is nothing we can add.

    – Ivan Stoev
    Dec 6 '17 at 20:11






  • 1





    @Ivan, please write this as an answer and I will mark it correct, it's exactly what I am looking for! I suspect I didn't find it while I was searching because, for me, I don't think of app server and database server in terms of client and server, though they certainly are, so I never searched with those words.

    – Brian Ball
    Dec 6 '17 at 21:40













3












3








3








I've been going through my application, and there are times where only part of the IQueryable is actually translated into a SQL query and the rest of the work is done in-memory.



I understand that there's no way for the EF team to account for every possible expression that a developer may come up with and magically translate that into a useable SQL query, but IIRC, EF would throw an exception if it was unable to translate ALL of the operations defined in an IQueryable to SQL.



Is there a way to have EF Core also throw an exception, or at the very least, raise an event when it's unable to fully translate an IQueryable into SQL?










share|improve this question














I've been going through my application, and there are times where only part of the IQueryable is actually translated into a SQL query and the rest of the work is done in-memory.



I understand that there's no way for the EF team to account for every possible expression that a developer may come up with and magically translate that into a useable SQL query, but IIRC, EF would throw an exception if it was unable to translate ALL of the operations defined in an IQueryable to SQL.



Is there a way to have EF Core also throw an exception, or at the very least, raise an event when it's unable to fully translate an IQueryable into SQL?







c# .net entity-framework-core






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 6 '17 at 19:39









Brian BallBrian Ball

8,99912740




8,99912740







  • 2





    See Client vs. Server Evaluation - Disabling client evaluation documentation topic - the explanation and example. I think there is nothing we can add.

    – Ivan Stoev
    Dec 6 '17 at 20:11






  • 1





    @Ivan, please write this as an answer and I will mark it correct, it's exactly what I am looking for! I suspect I didn't find it while I was searching because, for me, I don't think of app server and database server in terms of client and server, though they certainly are, so I never searched with those words.

    – Brian Ball
    Dec 6 '17 at 21:40












  • 2





    See Client vs. Server Evaluation - Disabling client evaluation documentation topic - the explanation and example. I think there is nothing we can add.

    – Ivan Stoev
    Dec 6 '17 at 20:11






  • 1





    @Ivan, please write this as an answer and I will mark it correct, it's exactly what I am looking for! I suspect I didn't find it while I was searching because, for me, I don't think of app server and database server in terms of client and server, though they certainly are, so I never searched with those words.

    – Brian Ball
    Dec 6 '17 at 21:40







2




2





See Client vs. Server Evaluation - Disabling client evaluation documentation topic - the explanation and example. I think there is nothing we can add.

– Ivan Stoev
Dec 6 '17 at 20:11





See Client vs. Server Evaluation - Disabling client evaluation documentation topic - the explanation and example. I think there is nothing we can add.

– Ivan Stoev
Dec 6 '17 at 20:11




1




1





@Ivan, please write this as an answer and I will mark it correct, it's exactly what I am looking for! I suspect I didn't find it while I was searching because, for me, I don't think of app server and database server in terms of client and server, though they certainly are, so I never searched with those words.

– Brian Ball
Dec 6 '17 at 21:40





@Ivan, please write this as an answer and I will mark it correct, it's exactly what I am looking for! I suspect I didn't find it while I was searching because, for me, I don't think of app server and database server in terms of client and server, though they certainly are, so I never searched with those words.

– Brian Ball
Dec 6 '17 at 21:40












1 Answer
1






active

oldest

votes


















3















Is there a way to have EF Core also throw an exception, or at the very least, raise an event when it's unable to fully translate an IQueryable into SQL?




Sure. First, this is a EF Core concept called client evaluation which didn't exist in pre EF Core (EF6.x). It's covered by the Client vs. Server Evaluation documentation topic, and Disabling client evaluation section explains the default behavior and how it can be changed:




By default, EF Core will log a warning when client evaluation is performed. See Logging for more information on viewing logging output. You can change the behavior when client evaluation occurs to either throw or do nothing. This is done when setting up the options for your context - typically in DbContext.OnConfiguring, or in Startup.cs if you are using ASP.NET Core.




The later is achieved by using ConfigureWarnings method of DbContextOptionsBuilder class for RelationalEventId.QueryClientEvaluationWarning. Valid actions are Log (default), Ignore and Throw (desired):



protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

// ...
optionsBuilder.ConfigureWarnings(warnings =>
warnings.Throw(RelationalEventId.QueryClientEvaluationWarning));






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47682200%2fhow-to-detect-when-ef-core-must-do-some-of-the-iqueryable-operations-in-memory%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3















    Is there a way to have EF Core also throw an exception, or at the very least, raise an event when it's unable to fully translate an IQueryable into SQL?




    Sure. First, this is a EF Core concept called client evaluation which didn't exist in pre EF Core (EF6.x). It's covered by the Client vs. Server Evaluation documentation topic, and Disabling client evaluation section explains the default behavior and how it can be changed:




    By default, EF Core will log a warning when client evaluation is performed. See Logging for more information on viewing logging output. You can change the behavior when client evaluation occurs to either throw or do nothing. This is done when setting up the options for your context - typically in DbContext.OnConfiguring, or in Startup.cs if you are using ASP.NET Core.




    The later is achieved by using ConfigureWarnings method of DbContextOptionsBuilder class for RelationalEventId.QueryClientEvaluationWarning. Valid actions are Log (default), Ignore and Throw (desired):



    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

    // ...
    optionsBuilder.ConfigureWarnings(warnings =>
    warnings.Throw(RelationalEventId.QueryClientEvaluationWarning));






    share|improve this answer





























      3















      Is there a way to have EF Core also throw an exception, or at the very least, raise an event when it's unable to fully translate an IQueryable into SQL?




      Sure. First, this is a EF Core concept called client evaluation which didn't exist in pre EF Core (EF6.x). It's covered by the Client vs. Server Evaluation documentation topic, and Disabling client evaluation section explains the default behavior and how it can be changed:




      By default, EF Core will log a warning when client evaluation is performed. See Logging for more information on viewing logging output. You can change the behavior when client evaluation occurs to either throw or do nothing. This is done when setting up the options for your context - typically in DbContext.OnConfiguring, or in Startup.cs if you are using ASP.NET Core.




      The later is achieved by using ConfigureWarnings method of DbContextOptionsBuilder class for RelationalEventId.QueryClientEvaluationWarning. Valid actions are Log (default), Ignore and Throw (desired):



      protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

      // ...
      optionsBuilder.ConfigureWarnings(warnings =>
      warnings.Throw(RelationalEventId.QueryClientEvaluationWarning));






      share|improve this answer



























        3












        3








        3








        Is there a way to have EF Core also throw an exception, or at the very least, raise an event when it's unable to fully translate an IQueryable into SQL?




        Sure. First, this is a EF Core concept called client evaluation which didn't exist in pre EF Core (EF6.x). It's covered by the Client vs. Server Evaluation documentation topic, and Disabling client evaluation section explains the default behavior and how it can be changed:




        By default, EF Core will log a warning when client evaluation is performed. See Logging for more information on viewing logging output. You can change the behavior when client evaluation occurs to either throw or do nothing. This is done when setting up the options for your context - typically in DbContext.OnConfiguring, or in Startup.cs if you are using ASP.NET Core.




        The later is achieved by using ConfigureWarnings method of DbContextOptionsBuilder class for RelationalEventId.QueryClientEvaluationWarning. Valid actions are Log (default), Ignore and Throw (desired):



        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

        // ...
        optionsBuilder.ConfigureWarnings(warnings =>
        warnings.Throw(RelationalEventId.QueryClientEvaluationWarning));






        share|improve this answer
















        Is there a way to have EF Core also throw an exception, or at the very least, raise an event when it's unable to fully translate an IQueryable into SQL?




        Sure. First, this is a EF Core concept called client evaluation which didn't exist in pre EF Core (EF6.x). It's covered by the Client vs. Server Evaluation documentation topic, and Disabling client evaluation section explains the default behavior and how it can be changed:




        By default, EF Core will log a warning when client evaluation is performed. See Logging for more information on viewing logging output. You can change the behavior when client evaluation occurs to either throw or do nothing. This is done when setting up the options for your context - typically in DbContext.OnConfiguring, or in Startup.cs if you are using ASP.NET Core.




        The later is achieved by using ConfigureWarnings method of DbContextOptionsBuilder class for RelationalEventId.QueryClientEvaluationWarning. Valid actions are Log (default), Ignore and Throw (desired):



        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

        // ...
        optionsBuilder.ConfigureWarnings(warnings =>
        warnings.Throw(RelationalEventId.QueryClientEvaluationWarning));







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 7 '17 at 1:42

























        answered Dec 7 '17 at 1:36









        Ivan StoevIvan Stoev

        102k772125




        102k772125



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47682200%2fhow-to-detect-when-ef-core-must-do-some-of-the-iqueryable-operations-in-memory%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            What does pagestruct do in Eviews?

            Dutch intervention in Lombok and Karangasem

            Channel Islands