以下 linq to entity 查询给出以下结果:
public class UserCountResult
{
public DateTime? date { get; set; } // **should this be string instead?**
public int users { get; set; }
public int visits { get; set; }
}
public JsonResult getActiveUserCount2(string from = "", string to = "")
{
var query = from s in db.UserActions
group s by EntityFunctions.TruncateTime(s.Date) into g
select new UserCountResult
{
date = g.Key, // can't use .toString("dd.MM.yyyy") here
users = g.Select(x => x.User).Distinct().Count(),
visits = g.Where(x => x.Category == "online").Select(x => x.Category).Count()
};
return Json(query, JsonRequestBehavior.AllowGet);
}
结果:
[{"date":"\/Date(1383433200000)\/","users":21,"visits":47},{"date":"\/Date(1383519600000)\/","users":91,"visits":236}]
而不是 /Date(1383433200000)/ 之类的东西,我需要格式为“dd.MM.yyyy”的日期,例如
[{"date":"29.11.2013","users":21,"visits":47},{"date":"30.11.2013","users":91,"visits":236}]
我找不到如何更改查询格式的方法,我不知道该怎么做..我什至不明白为什么 g.Key 可以为空..感谢您的任何输入!