LINQ Query ForEach无法使用 [英] LINQ Query ForEach cannot use
问题描述
我有一个AnonymuosType的LINQ结果",它的内部有一些实体对象,这些实体对象由LINQ从EF查询.
I have a LINQ "result" of anonymuosType, inside it, it have some entity object which query by LINQ from EF.
我想利用结果"来过滤实体对象并为"newResult"设置一些新值.
I would like to make used of the "result" to filter and set some new value on the entity object for the "newResult".
但是在"newResult"上的.Where()之后,我无法使用ForEach().
But I not able to use the ForEach(), after the .Where() on "newResult".
我可以知道我做错了什么吗?使用LINQ有其他替代解决方案吗? (我可以通过简单的foreach循环来实现它,但是我想通过LINQ来学习更多.)
May I know what I did wrong? Any alternative solution by using LINQ? (I can do simple foreach looping to achieve it, But I would like to learn more by using LINQ.)
var result = (from e in unmatch_epay_details
join w in DB.WatReconDetails
on e.RetTransRef equals w.RetTransRef
into a
from b in a.DefaultIfEmpty()
select new
{
ePayDetailID = e.ePayReconDetailID,
WATStatus = (b == default(WatReconDetail)) ? 0 : 1,//** if default return 0.
EpayInfo = e,
WATinfo = b
})
.OrderBy(a => a.ServerTransDateTime)
.ToList();
var newResult = result
.Where(a => a.EpayInfo.condition =="condition")
.ForEach(b => b.EpayInfo.result=="result");//I not able to use the foreach at here.
推荐答案
ForEach()
不是linq,它是List<T>
上的一个函数(并且您正在使用IEnumerable<T>
).
因此,请使用普通的foreach
.
ForEach()
is not linq, it is a function on List<T>
(and you are working with IEnumerable<T>
).
So use normal foreach
instead.
这篇关于LINQ Query ForEach无法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!