none
Filtering in LINQ query RRS feed

  • Question

  • Hi,

    I have an observable collection which would be bound to the silverlight datagrid, where i need to display a particular row based on the data present in the OC.

    ID Name status description role
    1 abc 500 desc 50
    1 abc 500 desc 55
    2 xyx 501 desc 51

    in the above table there are duplicate values, i need to filter them in such a way that when (status = 500) i need to pick the row which has  role as 50. or if the (status = 501) i need to pick the row which has role  as 55. In any instant the status would remain same for a particular ID. My final data should look like the one below.

     

    ID Name status description role
    1 abc 500 desc 50
    2 xyx 501 desc 51
    Saturday, December 18, 2010 11:50 AM

Answers

  • Hi,

     

    Not sure if I am able to get your point here but atleast your desired output can be obtained by looking for rows that have either status=500 and role=50 OR status=501 and role=55.

    from r in customers
    where 
     (r.status == 500 && r.role == 55) || 
     (r.status == 501 && r.role == 51)
    select r;
    


    If that isn't helpful, can you post some more data containing other possible scenarios, and your desired output?

     

    Regards,


    Syed Mehroz Alam
    My Blog | My Articles
    Monday, December 20, 2010 9:52 AM

All replies

  • hi

    I am afraid if you can do it all in a single query, instead you can break your complex query in some seperate queries and then combine the results.

     

    Regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Regards, Alireza
    Monday, December 20, 2010 8:45 AM
  • Hi,

     

    Not sure if I am able to get your point here but atleast your desired output can be obtained by looking for rows that have either status=500 and role=50 OR status=501 and role=55.

    from r in customers
    where 
     (r.status == 500 && r.role == 55) || 
     (r.status == 501 && r.role == 51)
    select r;
    


    If that isn't helpful, can you post some more data containing other possible scenarios, and your desired output?

     

    Regards,


    Syed Mehroz Alam
    My Blog | My Articles
    Monday, December 20, 2010 9:52 AM