如何在另一种方法中使用此LINQ的结果并获取属性CountryID
和count
?通过LINQ匿名类型对象迭代
public IQueryable GetRequestsByRegion(string RequestType)
{
try
{
var q = from re in context.RequestExtensions
from r in context.Requests
where re.ExtensionID == r.ExtraInfoID
&& r.OriginalRequestID == null
&& r.RequestType == RequestType
group re by new { CountryID = re.CountryID } into grouped
select new { CountryID = (int)grouped.Key.CountryID, count = (int)grouped.Count(t => t.CountryID != null) } ;
return q;
}
catch (Exception ex)
{
}
return null;
}
public void GetAllInformationRequestsByRegion()
{
IQueryable dict = GetRequestsByRegion("tab8elem1");
/* How to iterate and get the properties here? */
}
返回类型和变量类型不需要被指示......这只是我的尝试。我也使用WCF,所以我不能返回对象类型。
+1:一个简单的一天:) – leppie
对不起,我不能马上写这个,HANDELING这么多东西就溜:我想用这个函数内部,返回LINQ的结果,而不预处理,并处理它在其他方法上。我应该返回什么类型的方法以及如何处理调用方法上的对象?此外,使用WCF所以无法返回对象类型...谢谢你,并为不完整的问题抱歉。 –
@LuísSousa:你可以在'select g;'停下来并返回一个'IGrouping'。如果你想返回“最终”的对象,你应该为他们上课。 –
Jon