You could create an extension method along the lines of
public static IQueryable<T> BoolWhere<T>(this IQueryable<T> source, Expression<Func<T, TValue>> selector, bool isOr) {
//use isOr value to determine what expression to build and add to the source
}
where 'isOr' will determine whether to use an 'and' expression or an 'or' expression. Then you can construct your query along the lines of
bool isOr = true; //or false
var results = Data.BoolWhere(r => r.Id == criteria.SampleId, isOr)
.BoolWhere(r => r.Status.SampleStatusId == criteria.SampleStatusId, isOr)
.BoolWhere(r => r.Job.JobNumber.StartsWith(criteria.JobNumber), isOr)
.BoolWhere(r => r.Description.Contains(criteria.Description), isOr)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…