Entity framework 6 IQueryable does not update with separate calls











up vote
1
down vote

favorite












I have an unusual problem where by if I make separate calls to an IQueryable the initial call that creates the IQueryable will generate SQL specific to the first call. This can be seen when debugging and observing the internal query.



When I make inline calls such as:



IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking().Include(t=> t.someRefData).Where(t => t.Id >= 10);


this produces the correct internal SQL query.



However If I dynamically make the query with separate distinct calls such as:



IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking();
tEnt.Include(t=> t.someRefData);
tEnt.Where(t => t.Id >= 10);


The internal SQL query does not update beyond the declaration of tEnt to reflect these preceeding calls.



Have I total mis-understood how IQueryable works?










share|improve this question


















  • 3




    Include and Where return new IQueryable objects, you are discarding them.
    – DavidG
    2 days ago








  • 1




    Oh im so having a derp moment ofcourse they do. The calls dont apply to the calling object only create based on what was refered to it.
    – Gelion
    2 days ago










  • Btw. a IQueryable is a kind of concatenation of commands. Is used similar to IEnumerable, but the concated commands are not called until the IQueryable is converted into an object (.singe(); .first(); singleOrDefault(); .firstOrDefault()), into an array or into an IEnumerable (e.g. .ToList() ). befor that conversation it is just a command. Also: you have to make the call before you close your container, or you will get an exception, if you try to run your concatinated commands on a closed connection
    – Horitsu
    2 days ago















up vote
1
down vote

favorite












I have an unusual problem where by if I make separate calls to an IQueryable the initial call that creates the IQueryable will generate SQL specific to the first call. This can be seen when debugging and observing the internal query.



When I make inline calls such as:



IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking().Include(t=> t.someRefData).Where(t => t.Id >= 10);


this produces the correct internal SQL query.



However If I dynamically make the query with separate distinct calls such as:



IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking();
tEnt.Include(t=> t.someRefData);
tEnt.Where(t => t.Id >= 10);


The internal SQL query does not update beyond the declaration of tEnt to reflect these preceeding calls.



Have I total mis-understood how IQueryable works?










share|improve this question


















  • 3




    Include and Where return new IQueryable objects, you are discarding them.
    – DavidG
    2 days ago








  • 1




    Oh im so having a derp moment ofcourse they do. The calls dont apply to the calling object only create based on what was refered to it.
    – Gelion
    2 days ago










  • Btw. a IQueryable is a kind of concatenation of commands. Is used similar to IEnumerable, but the concated commands are not called until the IQueryable is converted into an object (.singe(); .first(); singleOrDefault(); .firstOrDefault()), into an array or into an IEnumerable (e.g. .ToList() ). befor that conversation it is just a command. Also: you have to make the call before you close your container, or you will get an exception, if you try to run your concatinated commands on a closed connection
    – Horitsu
    2 days ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have an unusual problem where by if I make separate calls to an IQueryable the initial call that creates the IQueryable will generate SQL specific to the first call. This can be seen when debugging and observing the internal query.



When I make inline calls such as:



IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking().Include(t=> t.someRefData).Where(t => t.Id >= 10);


this produces the correct internal SQL query.



However If I dynamically make the query with separate distinct calls such as:



IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking();
tEnt.Include(t=> t.someRefData);
tEnt.Where(t => t.Id >= 10);


The internal SQL query does not update beyond the declaration of tEnt to reflect these preceeding calls.



Have I total mis-understood how IQueryable works?










share|improve this question













I have an unusual problem where by if I make separate calls to an IQueryable the initial call that creates the IQueryable will generate SQL specific to the first call. This can be seen when debugging and observing the internal query.



When I make inline calls such as:



IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking().Include(t=> t.someRefData).Where(t => t.Id >= 10);


this produces the correct internal SQL query.



However If I dynamically make the query with separate distinct calls such as:



IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking();
tEnt.Include(t=> t.someRefData);
tEnt.Where(t => t.Id >= 10);


The internal SQL query does not update beyond the declaration of tEnt to reflect these preceeding calls.



Have I total mis-understood how IQueryable works?







linq entity-framework-6 iqueryable






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









Gelion

152313




152313








  • 3




    Include and Where return new IQueryable objects, you are discarding them.
    – DavidG
    2 days ago








  • 1




    Oh im so having a derp moment ofcourse they do. The calls dont apply to the calling object only create based on what was refered to it.
    – Gelion
    2 days ago










  • Btw. a IQueryable is a kind of concatenation of commands. Is used similar to IEnumerable, but the concated commands are not called until the IQueryable is converted into an object (.singe(); .first(); singleOrDefault(); .firstOrDefault()), into an array or into an IEnumerable (e.g. .ToList() ). befor that conversation it is just a command. Also: you have to make the call before you close your container, or you will get an exception, if you try to run your concatinated commands on a closed connection
    – Horitsu
    2 days ago














  • 3




    Include and Where return new IQueryable objects, you are discarding them.
    – DavidG
    2 days ago








  • 1




    Oh im so having a derp moment ofcourse they do. The calls dont apply to the calling object only create based on what was refered to it.
    – Gelion
    2 days ago










  • Btw. a IQueryable is a kind of concatenation of commands. Is used similar to IEnumerable, but the concated commands are not called until the IQueryable is converted into an object (.singe(); .first(); singleOrDefault(); .firstOrDefault()), into an array or into an IEnumerable (e.g. .ToList() ). befor that conversation it is just a command. Also: you have to make the call before you close your container, or you will get an exception, if you try to run your concatinated commands on a closed connection
    – Horitsu
    2 days ago








3




3




Include and Where return new IQueryable objects, you are discarding them.
– DavidG
2 days ago






Include and Where return new IQueryable objects, you are discarding them.
– DavidG
2 days ago






1




1




Oh im so having a derp moment ofcourse they do. The calls dont apply to the calling object only create based on what was refered to it.
– Gelion
2 days ago




Oh im so having a derp moment ofcourse they do. The calls dont apply to the calling object only create based on what was refered to it.
– Gelion
2 days ago












Btw. a IQueryable is a kind of concatenation of commands. Is used similar to IEnumerable, but the concated commands are not called until the IQueryable is converted into an object (.singe(); .first(); singleOrDefault(); .firstOrDefault()), into an array or into an IEnumerable (e.g. .ToList() ). befor that conversation it is just a command. Also: you have to make the call before you close your container, or you will get an exception, if you try to run your concatinated commands on a closed connection
– Horitsu
2 days ago




Btw. a IQueryable is a kind of concatenation of commands. Is used similar to IEnumerable, but the concated commands are not called until the IQueryable is converted into an object (.singe(); .first(); singleOrDefault(); .firstOrDefault()), into an array or into an IEnumerable (e.g. .ToList() ). befor that conversation it is just a command. Also: you have to make the call before you close your container, or you will get an exception, if you try to run your concatinated commands on a closed connection
– Horitsu
2 days ago












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










tEnt = tEnt.Include(t=> t.someRefData);





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',
    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%2f53373692%2fentity-framework-6-iqueryable-does-not-update-with-separate-calls%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








    up vote
    1
    down vote



    accepted










    tEnt = tEnt.Include(t=> t.someRefData);





    share|improve this answer



























      up vote
      1
      down vote



      accepted










      tEnt = tEnt.Include(t=> t.someRefData);





      share|improve this answer

























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        tEnt = tEnt.Include(t=> t.someRefData);





        share|improve this answer














        tEnt = tEnt.Include(t=> t.someRefData);






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 days ago









        Logan

        2,08932856




        2,08932856










        answered 2 days ago









        Horitsu

        206210




        206210






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373692%2fentity-framework-6-iqueryable-does-not-update-with-separate-calls%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







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith