❔ Replacing joins to a table with a CTE in EF Core
Say I generate my sql with ef core. Is there a way to make it do joins on the CTE rather than the original table? So for example if I do a
Can I make the join with projects use a CTE, so it looks kinda like this:
Generating a query that's similar to this:
To be clear, what I want is for all joins with the projects table to be substituted for a join to a CTE.
Since I think EF Core cannot generate CTE's, is there a way to just force it to replace joins with the Projects table to
view
, which I would then append to the SQL query as text? I guess an idea is to replace the strings which reference the Projects table after it generates the SQL, but is there a way to do this at one higher level of abstraction?
Is my idea flawed, or is there a simpler way, you think?
The same can kinda be achieved with nested queries on all nested fields, but my problem with this is that it requires redoing the projections. Thinking of the Projects table as a view feels simpler in this case.2 Replies