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. Using LINQ on an ObservableCollection<t></t>

Using LINQ on an ObservableCollection<t></t>

Scheduled Pinned Locked Moved LINQ
csharpvisual-studiohelpquestiondatabase
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.
  • B Offline
    B Offline
    bluewavestrider
    wrote on last edited by
    #1

    Hello Guys, I already asked this question under WPF forum, but since a portion of my code is LINQ, well here you go. I have a class <code>Client</code> of which I use to return a collection of clients from the database as an ObservableCollection:

    ObservableCollection<Client> myClients = queries.GetClients();

    where GetClients() is a method that returns a list of clients of type ObservableCollection<Client> Now I use LINQ to run a search for clients as follows:

            ObservableCollection<Client> filteredClients = null;
            IEnumerable<Client> qry = from c in myClients
                                      where c.Name.ToUpper().Contains(txtSearch.Text.ToUpper())
                                      orderby c.Name
                                      select c;
    
            filteredClients = new ObservableCollection<Client>(qry);
    

    Hence filteredClients is supposed to contain a subset of myClients of the same type ObservableCollection<Client> My problem is that this works fine on my x64 vista/machine, but when I move it to my x86 vista/machine I get an error that:

    Argument '1': cannot convert from 'System.Collections.Generic.IEnumerable<Client>' to 'System.Collections.Generic.List<Client>'

    After poking around a bit, I discovered that in my Visual Studio (both machines run VS.NET 2008 on Framework 3.5) on the x64 machine, the ObservableCollection<T> class has 3 overloads and one of them accepts an IEnumerable<T>```` , which is exactly what `qry` above is. However, on my x86 as you can guess, there are only 2 constructors and ``` IEnumerable<T>``; isn't one of the parameters. Just an empty overload and one that receives a `List<T>` So then my question is why is there this disparity in the number of overloads on vista x64 platform and vista x86? Does this mean that I would have to design an auxiliary class that'll return a List<T> from my backend rather than `an ObservableCollection<T>` for x86 platforms? P.S: That is just one of the compatibility problems I believe those of us building applications with WPF are facing. Another one I hit is that if I have a ListBox with a DataTemplate and I set its SelectedValuePath, it works fine on my x64 machine but appears null on my x86 machine. My 2 pennies for other deve`` ``` ````

    A 1 Reply Last reply
    0
    • B bluewavestrider

      Hello Guys, I already asked this question under WPF forum, but since a portion of my code is LINQ, well here you go. I have a class <code>Client</code> of which I use to return a collection of clients from the database as an ObservableCollection:

      ObservableCollection<Client> myClients = queries.GetClients();

      where GetClients() is a method that returns a list of clients of type ObservableCollection<Client> Now I use LINQ to run a search for clients as follows:

              ObservableCollection<Client> filteredClients = null;
              IEnumerable<Client> qry = from c in myClients
                                        where c.Name.ToUpper().Contains(txtSearch.Text.ToUpper())
                                        orderby c.Name
                                        select c;
      
              filteredClients = new ObservableCollection<Client>(qry);
      

      Hence filteredClients is supposed to contain a subset of myClients of the same type ObservableCollection<Client> My problem is that this works fine on my x64 vista/machine, but when I move it to my x86 vista/machine I get an error that:

      Argument '1': cannot convert from 'System.Collections.Generic.IEnumerable<Client>' to 'System.Collections.Generic.List<Client>'

      After poking around a bit, I discovered that in my Visual Studio (both machines run VS.NET 2008 on Framework 3.5) on the x64 machine, the ObservableCollection<T> class has 3 overloads and one of them accepts an IEnumerable<T>```` , which is exactly what `qry` above is. However, on my x86 as you can guess, there are only 2 constructors and ``` IEnumerable<T>``; isn't one of the parameters. Just an empty overload and one that receives a `List<T>` So then my question is why is there this disparity in the number of overloads on vista x64 platform and vista x86? Does this mean that I would have to design an auxiliary class that'll return a List<T> from my backend rather than `an ObservableCollection<T>` for x86 platforms? P.S: That is just one of the compatibility problems I believe those of us building applications with WPF are facing. Another one I hit is that if I have a ListBox with a DataTemplate and I set its SelectedValuePath, it works fine on my x64 machine but appears null on my x86 machine. My 2 pennies for other deve`` ``` ````

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

      Posted a response[^] in the WPF forum

      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