改变查询表达式 post 创建
Altering Query expression post creation
我正在尝试创建一个新查询,然后根据特定条件对其进行编辑和添加。括号[]
中写的函数我不知道怎么做
/* Create the query */
var query = from quote in Query()
where quote.documentNum = document_Input
select quote;
// Now change the sort field
query = filter.sort == SortFied.quote ? [alter the query function to sort by documentNum<string>] : [alter the query function to sort by enteredData<DateTime?>]
// Now change the sort direction
query = filter.sortDir == SortDirection.Ascending ? [alter the query to sort in an Ascending order] : [alter the query to sort in an Descending order]
这只是两个必须添加的条件afterwards.The之后添加它的目的是避免每个可能的条件重复代码。
我假设是这样的。
var query = Query().Where(x => x.documentNum == document_Input);
query = filter.sortDir == SortDirection.Ascending ? query.OrderBy(x => filter.sort == SortFied.quote ? x.documentNum : x.enteredData) : query.OrderByDescending(x => filter.sort == SortFied.quote ? x.documentNum : x.enteredData);
您可以通过使用委托进一步减少代码重复。
我正在尝试创建一个新查询,然后根据特定条件对其进行编辑和添加。括号[]
中写的函数我不知道怎么做/* Create the query */
var query = from quote in Query()
where quote.documentNum = document_Input
select quote;
// Now change the sort field
query = filter.sort == SortFied.quote ? [alter the query function to sort by documentNum<string>] : [alter the query function to sort by enteredData<DateTime?>]
// Now change the sort direction
query = filter.sortDir == SortDirection.Ascending ? [alter the query to sort in an Ascending order] : [alter the query to sort in an Descending order]
这只是两个必须添加的条件afterwards.The之后添加它的目的是避免每个可能的条件重复代码。
我假设是这样的。
var query = Query().Where(x => x.documentNum == document_Input);
query = filter.sortDir == SortDirection.Ascending ? query.OrderBy(x => filter.sort == SortFied.quote ? x.documentNum : x.enteredData) : query.OrderByDescending(x => filter.sort == SortFied.quote ? x.documentNum : x.enteredData);
您可以通过使用委托进一步减少代码重复。