开发者

Linq Filtering Question

开发者 https://www.devze.com 2023-03-28 08:39 出处:网络
Guys actually i wanna make a query like this: var firstTakeIssues = _db.Query<Issue>().OrderByDescending(i => i.CreatedDate)

Guys actually i wanna make a query like this:

var firstTakeIssues = _db.Query<Issue>().OrderByDescending(i => i.CreatedDate)
                          .Take(take)
                          .Having(i => i.Project.ProjectID in IEnumerable<int>)
                       开发者_如何学Go   .Select(i => new {
                                  IssueId = i.IssueID,
                                  State = (StateEnum)i.State,
                                  ProjectName = i.Project.Name,
                                  Priority = (PriorityEnum)i.Priority,
                                  CreatedAt = i.CreatedDate,
                                  PostedBy = i.Client.Name
                              }).ToList();

I know that this dont work, but what i want to do is:

  1. search by projects in a collection
  2. order by created date
  3. select just a set of data
  4. obtain a subset of columns

What i really want to point is that i dont know how to make a query with having clause.


To emulate your "having" clause, I believe you should be able to use a Where along with Contains:

var projectIds = new int[] { 1, 2, 4, 6 };
var firstTakeIssues = _db.Query<Issue>()
                         .OrderByDescending(i => i.CreatedDate)
                         .Take(take)
                         .Where(i => projectIds.Contains(i.Project.ProjectID))
                         .Select(i => new {
                              IssueId = i.IssueID,
                              State = (StateEnum)i.State,
                              ProjectName = i.Project.Name,
                              Priority = (PriorityEnum)i.Priority,
                              CreatedAt = i.CreatedDate,
                              PostedBy = i.Client.Name
                          }).ToList();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号