Here is the code I am using:
Code: Select all
using (RTPDataContext context = new RTPDataContext())
{
DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith(t => t.Application);
dlo.LoadWith(t => t.Sponsor);
context.LoadOptions = dlo;
var x = (from t in context.Tournaments
orderby t.Id
select t).ToList();
}
The SQL that is generated is as follows:
Code: Select all
SELECT t1."TournamentId", t1."TournamentName", t1."TournamentDateAdded", t1."ApplicationId_FK", t1."TournamentStartDate", t1."TournamentEndDate", t1."TournamentRoundsNumber", t1."TournamentStatus", t1."TournamentDescription", t1."SponsorId_FK", t1."TournamentNote", t3."ApplicationId", t3."ApplicationDateAdded", t3."PartnerId_FK", t3."ApplicationName", t3."ApplicationPostBackURL", t3."ApplicationIPAddress", t3."ApplicationClientSecretKey", t3."ApplicationEngineSecretKey", t3."ApplicationNote"
FROM (
SELECT t2."TournamentId", t2."TournamentName", t2."TournamentDateAdded", t2."ApplicationId_FK", t2."TournamentStartDate", t2."TournamentEndDate", t2."TournamentRoundsNumber", t2."TournamentStatus", t2."TournamentDescription", t2."SponsorId_FK", t2."TournamentNote"
FROM public."RTPTournament" t2
ORDER BY t2."TournamentId"
) t1
INNER JOIN public."RTPApplication" t3 ON t1."ApplicationId_FK" = t3."ApplicationId"
ORDER BY t1."ApplicationId_FK"
-- Context: Devart.Data.PostgreSql.Linq.Provider.PgSqlDataProvider Model: an Build: 2.0.7.0
SELECT t1."SponsorId", t1."SponsorName", t1."SponsorDateAdded", t1."SponsorImageURL", t1."SponsorURL", t1."SponsorStatus", t1."SponsorNote"
FROM public."RTPSponsor" t1
WHERE :np0 = t1."SponsorId"
-- np0: Input BigInt (Size = 0; DbType = Int64) [1]
-- Context: Devart.Data.PostgreSql.Linq.Provider.PgSqlDataProvider Model: an Build: 2.0.7.0
The second issue is that i wanted to order by "TournamentId", but the query actually returns the records sorted by "ApplicationId", since that order by is for some reason applied to the outer query whereas the "TournamentId" order by is applied to the inner query.
If possible I would also like to get rid of the nested query entirely since it is not necessary here.
Anyway, if someone could please help me fix these issues, or let me know if they are not possible to fix I would appreciate it. Thanks.