Generic Entity Framework Query in CQRS
I'll give it a shot since CQRS is something I'm still learning.

In CQRS we are supposed to separate our read model from our write model. Is this what you have done?

Then the read model should be designed to be a perfect fit for the thing that needs to read it:


Your query looks very complex. Is it derived from the write model, or do you indeed have separate tables for the queries?
Why a Func as a parameter? It seems strange to me that the criteria should be a negotiation between client and query.
Why do you put the query method onto the DbContext? That class will soon enough be cluttered with too many queries.


Here are some suggestions to simplify things:


Let the DbContext mimic the database tables only and nothing else. That means your DbContext will only have public properties for the tables you are going to query.
Don't call it a Repository, but a Query. Split the Query-class when it grows too big.
Let the Query class take the DbContext as a dependency. Query the DbContext-properties, don't use Set&lt;T&gt;.
Let each query-method accept one criteria object as parameter, then build the query expression from that inside the method.
Linq is tricky. While not entirely true, a rule of thumb is that a Func runs client side, while an Expression runs server side. That's also why I don't like the Func-parameter.
Consider using only non-generic query-methods. Yes, there will be some duplication, but you want your peers and the future you to understand the queries two months from now.


I meant to post some code examples, but Chrome crashed again and edits got lost :-(