更改表值时未更新Linq [英] Linq Not Updatd When Changeing Table Value
问题描述
是否有任何选项可以使用linq来获取更新的数据,而无需重新查询可查询对象
Is there any option get the updated data using linq without requering the quriable object
推荐答案
您实际上有点不精确,但我会尝试:
假设您有:
Hi,
you are in fact a little unprecise, but I''ll try:
Assume you have:
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;
每当您添加另一个数字(比方说:13)时,随后的赔率调用将自动反映更改(新结果是:1、3、5、7、13).如果是您所要求的,那就没有选择,也没有必要.
如果您正在考虑以下内容:
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:
// continue the above code
List<int> oddnumbers = odds.ToList();
numbers.Add(13);
那么奇数"是一个完全新的对象,与数字"或奇数"无关/没有链接.因此它不包含"13".当您在查询定义语句(或"ToArray()"或"let")中使用ToList()方法时,也是如此.
如果您需要反映数字"中的更改,则可以使用ObservableCollection而不是List并在CollectionChanged事件上重新查询.但是,如果要处理大型结果集,请务必留意您的记忆.
干杯
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
这篇关于更改表值时未更新Linq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!