Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

Is there any option get the updated data using linq without requering the quriable object
Posted
Comments
Prerak Patel 27-Jul-11 1:13am    
Elaborate more.

1 solution

Hi,

you are in fact a little unprecise, but I'll try:

Assume you have:
C#
List<int> numbers = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7 });
var odds =
   from number in numbers
   where (number % 2) == 1
   select number;

Whenever you add another number (let's say: 13) a subsequent call to odds will automatically reflect the changes (the new result is: 1,3,5,7,13). If that is, what you asked, then there is no option and there is no need for.

If you're thinking of something like:
C#
// continue the above code
List<int> oddnumbers = odds.ToList();
numbers.Add(13);

then 'oddnumbers' is a completly new object that has nothing to do with/no link to 'numbers' or 'odds'. So it does not contain the '13'. The same applies when you're using the ToList()-method in the query definition statement (or 'ToArray()' or 'let').

If you need to reflect changes in 'numbers', you could use an ObservableCollection instead of a List and requery upon the CollectionChanged-event. But be sure to keep an eye on your memory if you're dealing with large resultsets.

Cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900