Is there any way to tell if a table has already been joined in a SqlExpression<T>?
I need to automatically add join a table onto a base query for ordering purposes, but the table should only be joined if it wasn’t already joined in the base query.
Base query:
SELECT "Order"."Id", "Order"."SalesChannelId", "Order"."DateCreated"
FROM "Order"
WHERE "DateCreated" > '20150101'
Query with ordering:
SELECT "Order"."Id", "Order"."SalesChannelId", "Order"."DateCreated"
FROM "Order"
INNER JOIN "SalesChannel" ON "SalesChannel"."Id" = "Order"."SalesChannelId"
WHERE "DateCreated" > '20150101'
ORDER BY "SalesChannel"."Name"
I see there is the IsJoinedTable(Type type) method, but it’s private. It would be helpful if you make that method public.
Exposing IsJoinedTable(Type type) should be all I need for this. I would be using a runtime type, so IsJoinedTable<T> won’t work.
It would be nice to know the join type (e.g. INNER, LEFT, etc), but that is not strictly necessary for my purposes.
The use case is simply to automatically add an order by expression from a string like "SalesChannelId DESC". But in this case, SalesChannelId is a FK to a the SalesChannel table, so I wan’t to allow that to be automatically replaced with "SalesChannel"."Name" DESC. This will be used for dynamically ordering data displayed in a grid view.