Linq Filtering Question
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:
- search by projects in a collection
- order by created date
- select just a set of data
- 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();
精彩评论