Try with:
var images = db.query(@"SELECT t1.* FROM Images t1 LEFT JOIN Property t2 ON
t1.ImageID = t2.Primary_Image WHERE t1.PropertyID = @0 ORDER BY
t2.Primary_Image DESC", PropertyID);
With this query you filter the records from Images
that have a given PropertyID
joining with the matching rows of Property
.
Since only the primary image has a matching row in Property
, this record is the only that has a value in Primary_Image
: ordering in descending order puts this record at the first place.