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. linq accessing ui control values and sending results to backgroundworker [modified]

linq accessing ui control values and sending results to backgroundworker [modified]

Scheduled Pinned Locked Moved LINQ
databasecsharplinqdesignhelp
2 Posts 2 Posters 3 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.
  • L Offline
    L Offline
    Leblanc Meneses 0
    wrote on last edited by
    #1

    I have a linq query accessing ui control values and sending results to backgroundworker. Here is the goal.

            // query accessing ui controls
            var crossjoin\_forumquestion = from businessid in new List<Int32>() { 1, 2, 3, 4, 5 } 
                                          from yearid in new List<Int32>() { }.DefaultIfEmpty() 
                                          select new { BusinessID = businessid, YearID = yearid };
    
            
            // background worker will use the results as follows and do bulk inserts in db
            crossjoin\_forumquestion.Count();
            foreach (var row in crossjoin\_forumquestion) { }
    

    if i'm going be sending data outside the scope of the function it needs to be typed so. i created CrossJoinResult class, modified var to IEnumerable<CrossJoinResult> crossjoin_forumquestion = and changed select new to select new CrossJoinResult. however it looks like dowork event is throwing exception that query is outside the ui thread. sounds like the linq query is lazy loading. I need it to be fetched before i send the IEnumerable off to my dowork. my current fix is:

            AsyncData threaddata = new AsyncData();
            threaddata.CrossJoinResult =  new List<CrossJoinResult>(crossjoin\_forumquestion);
    

    //one of the overloads of a list takes in IEnumerable which extracts the data out the linq query.
    //i would like the proper solution in telling linq to give me the result set now.

    thanks, -lm

    modified on Thursday, October 2, 2008 10:29 PM

    P 1 Reply Last reply
    0
    • L Leblanc Meneses 0

      I have a linq query accessing ui control values and sending results to backgroundworker. Here is the goal.

              // query accessing ui controls
              var crossjoin\_forumquestion = from businessid in new List<Int32>() { 1, 2, 3, 4, 5 } 
                                            from yearid in new List<Int32>() { }.DefaultIfEmpty() 
                                            select new { BusinessID = businessid, YearID = yearid };
      
              
              // background worker will use the results as follows and do bulk inserts in db
              crossjoin\_forumquestion.Count();
              foreach (var row in crossjoin\_forumquestion) { }
      

      if i'm going be sending data outside the scope of the function it needs to be typed so. i created CrossJoinResult class, modified var to IEnumerable<CrossJoinResult> crossjoin_forumquestion = and changed select new to select new CrossJoinResult. however it looks like dowork event is throwing exception that query is outside the ui thread. sounds like the linq query is lazy loading. I need it to be fetched before i send the IEnumerable off to my dowork. my current fix is:

              AsyncData threaddata = new AsyncData();
              threaddata.CrossJoinResult =  new List<CrossJoinResult>(crossjoin\_forumquestion);
      

      //one of the overloads of a list takes in IEnumerable which extracts the data out the linq query.
      //i would like the proper solution in telling linq to give me the result set now.

      thanks, -lm

      modified on Thursday, October 2, 2008 10:29 PM

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Linq uses something called deferred execution which basically means you don't get the data until you evaluate it (in whichever way you see fit). If you want to export this as a list, you can just use crossjon_forumquestion.ToList(); to return a list.

      Deja View - the feeling that you've seen this post before.

      My blog | My articles | MoXAML PowerToys

      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