数据库:Mongodb,driver:C sharp Mongodb
现有一个类如下:
public class Threading
{
public MongoDB.Oid Id { get; set; }
public string Title { get; set; }
public string Summary { get; set; }
public MongoDB.Oid InfoType { get; set; }
public string CreatedBy { get; set; }
public DateTime CreatedTime { get; set; }
public string LastUpdatedBy { get; set; }
public DateTime LastUpdatedTime { get; set; }
}
查询条件类如下:
public class ThreadingSearchCriteria
{
public string ContainsKey { get; set; }
public string IgnoreKey { get; set; }
public MongoDB.Oid InfoType { get; set; }
public DateTime CutoffDate { get; set; }
}
var grouping = Enumerable.ToList(
from p in threading.Linq()
where p.Title.Contains(searchCriteria.ContainsKey) &&
p.Summary.Contains(searchCriteria.ContainsKey) &&
!p.Title.Contains(searchCriteria.IgnoreKey) &&
!p.Summary.Contains(searchCriteria.IgnoreKey) &&
p.InfoType ==searchCriteria.InfoType &&
p.LastUpdatedTime >= searchCriteria.CutoffDate
group p by p.InfoType into g
select new
{
Key = g.Key,
Count = g.Count()
});