0

我的查询是这样的,

var currentUsrId = Convert.ToInt16(Membership.GetUser().ProviderUserKey);
var Ids = Context.audits
          .Where(i => i.usr_id == currentUsrId)
          .Select(i => new
                 {
                      profile_id = i.profile_id
                 }).ToArray();

for ( var m=0; m < (Ids.Length); m++)
{
    var Query = Context.audits
                .Where(j => j.usr_id == currentUsrId && j.profile_id == Convert.ToInt16(Ids[m].profile_id))
                .Select(j => j.profile_id).Count();

    var TotalQuery = Context.audits
                     .Where(i => i.usr_id == currentUsrId)
                     .Select(i => new
                     {
                         Id = currentUsrId,
                         count = Query
                     }).Distinct().ToArray();

    //return json(TotalQuery,JsonRequestBehavior.AllowGet);
    ----strucked at this part-----
}

我想使用for循环发送记录,我想知道如何发送这些值,如果我在循环内使用return json,循环只执行一次

4

1 回答 1

0

尝试这样的事情:

List<T> queries = new List<T>();

for ( var m=0; m < (Ids.Length); m++)
{
    var Query = Context.audits
                .Where(j => j.usr_id == currentUsrId && j.profile_id == Convert.ToInt16(Ids[m].profile_id))
                .Select(j => j.profile_id).Count();

    var TotalQuery = Context.audits
                     .Where(i => i.usr_id == currentUsrId)
                     .Select(i => new
                     {
                         Id = currentUsrId,
                         count = Query
                     }).Distinct().ToArray();

    queries.add(TotalQuery);
}

return json(queries,JsonRequestBehavior.AllowGet);
于 2012-12-06T07:47:25.797 回答