I would probably write the query as follows:
IQueryable<O> query = context.Obj; if (A != null) query = query.Where(o => oA == A); var list = query.ToList()
This is not one expression, but I think it is quite readable.
Also, this code assumes context.Obj
is an IQueryable<O>
(for example, you are using LINQ to SQL). If not, just use IEnumerable<O>
.
svick source share