如何在另一种方法中使用此LINQ的结果并获取属性CountryID和count?
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? */
}
Run Code Online (Sandbox Code Playgroud)
返回类型和变量类型不需要是指示的......这只是我的尝试.我也在使用WCF,所以我不能返回对象类型.
就像它是任何其他类型的对象一样:
foreach(var obj in q) {
var id = obj.CountryID;
var count = obj.count;
}
Run Code Online (Sandbox Code Playgroud)