Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. deferred loading in LINQ

deferred loading in LINQ

Scheduled Pinned Locked Moved LINQ
csharpdatabaseasp-netlinqquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 3981366
    wrote on last edited by
    #1

    hi Lst's we have 2 queries to get data in LInq to sql + asp.net 3.5 //------deferred loading---//

    var result = from user in DBContext.Users
    select user;

             foreach (User u in result)
             {
    
             }
    

    //------immediate loading---//

    List result = (from user in DBContext.Users
    select user).ToList();

    I want to know -- accrding to defereed loading the queries should be executed only when it's requested in for each loop.and in immediate load we get all data at once. but doesn't query executes on var result =..stmnt.?

    A 1 Reply Last reply
    0
    • M Member 3981366

      hi Lst's we have 2 queries to get data in LInq to sql + asp.net 3.5 //------deferred loading---//

      var result = from user in DBContext.Users
      select user;

               foreach (User u in result)
               {
      
               }
      

      //------immediate loading---//

      List result = (from user in DBContext.Users
      select user).ToList();

      I want to know -- accrding to defereed loading the queries should be executed only when it's requested in for each loop.and in immediate load we get all data at once. but doesn't query executes on var result =..stmnt.?

      A Offline
      A Offline
      ABitSmart
      wrote on last edited by
      #2

      Member 3981366 wrote:

      I want to know -- accrding to defereed loading the queries should be executed only when it's requested in for each loop.and in immediate load we get all data at once.

      Yes, you are absolutely correct.Just to be precise, query is executed once and result is then iterated in the foreach loop.

      Member 3981366 wrote:

      but doesn't query executes on var result =..stmnt.?

      No it does not. You have yourself demonstrated it in your examples. To make things more clear, read the "Defered Query Evaluation" section from here[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups