I am trying to sort an OrmLite expression by a DateTime
field CreatedDate
descending but the logged SQL shows that DESC
isn’t being included. Switching to sorting by the Id
field the SQL is correct. I’m using the SqlExpression in a call to SelectMulti()
but if I use Select()
then DESC
will be included correctly.
Is there something wrong with the way I create the SqlExpression
?
var q = db.From<Notification>()
.Join<UserAuth>()
.Join<UserAuth, UserAuthRole>()
.Where<UserAuthRole>(r => r.RefId == companyId && r.RefIdStr == nameof(Company))
.OrderByDescending<Notification>(n => n.CreatedDate);
return db.SelectMulti<Notification, UserAuth>(q);
Here is the resulting SQL from the log;
SELECT "Notification".*, 0 EOT, "UserAuth".*, 0 EOT
FROM "Notification" INNER JOIN "UserAuth" ON
("UserAuth"."Id" = "Notification"."UserAuthId") INNER JOIN "UserAuthRole" ON
("UserAuth"."Id" = "UserAuthRole"."UserAuthId")
WHERE (("UserAuthRole"."RefId" = @0) AND ("UserAuthRole"."RefIdStr" = @1))
ORDER BY "Notification"."CreatedDate"
PARAMS: @0=1, @1=Company
Which works with Id
;
SELECT "Notification".*, 0 EOT, "UserAuth".*, 0 EOT
FROM "Notification" INNER JOIN "UserAuth" ON
("UserAuth"."Id" = "Notification"."UserAuthId") INNER JOIN "UserAuthRole" ON
("UserAuth"."Id" = "UserAuthRole"."UserAuthId")
WHERE (("UserAuthRole"."RefId" = @0) AND ("UserAuthRole"."RefIdStr" = @1))
ORDER BY "Notification"."Id" DESC
PARAMS: @0=1, @1=Company
Or when not selecting multi;
SELECT "Notification"."UserAuthId", "Notification"."NotificationTemplateId", "Notification"."DataValues", "Notification"."Message", "Notification"."Html", "Notification"."Text", "Notification"."Result", "Notification"."Id", "Notification"."CreatedBy", "Notification"."ModifiedBy", "Notification"."CreatedDate", "Notification"."ModifiedDate"
FROM "Notification" INNER JOIN "UserAuth" ON
("UserAuth"."Id" = "Notification"."UserAuthId") INNER JOIN "UserAuthRole" ON
("UserAuth"."Id" = "UserAuthRole"."UserAuthId")
WHERE (("UserAuthRole"."RefId" = @0) AND ("UserAuthRole"."RefIdStr" = @1))
ORDER BY "Notification"."CreatedDate" DESC
PARAMS: @0=1, @1=Company