I don't know of any way how to create efficient SQL like this, using a LINQ statement. But you can use:
- Use a stored procedure (or function), and call the stored procedure from LINQ.
- Use Direct SQL
Sure you can use a lot of inline conditional statements (? :
), but I don't think the result will be efficient.