正如kyndigs在他的评论中提到的那样,唯一的解决方案是使用? :
三级运算符伪造一个 switch 语句:
internal static readonly Func<MyEntities, long, MessageSortField, int, int, IQueryable<Model.Message>> MessagesPagedSortedAscQuery =
CompiledQuery.Compile((MyEntities db, long folderId, MessageSortField sortField, int skip, int take) =>
(
sortField == MessageSortField.Date ? db.Messages.Where(e => e.FolderId == folderId).OrderBy(m => m.Date).Skip(skip).Take(take) :
sortField == MessageSortField.Subject ? db.Messages.Where(e => e.FolderId == folderId).OrderBy(m => m.Subject).Skip(skip).Take(take) :
sortField == MessageSortField.From ? db.Messages.Where(e => e.FolderId == folderId).OrderBy(m => m.From).Skip(skip).Take(take) :
db.Messages.Where(e => e.FolderId == folderId).Skip(skip).Take(take)
));