In SQL it is possible to join with LIKE. Perhaps not the best idea always, but certainly useful.
This query:
var q = db.From<Tag>().Join<TagAccess>((t, a) => a.TagPath.StartsWith(t.Text))
.Where<TagAccess>(a => a.Username == username);
When I do .ToSqlStatementMergedParams
it gives me the incorrect SQL:
SELECT "Tag"."Id", "Tag"."Text", "Tag"."Type", "Tag"."Comment"
FROM "Tag" INNER JOIN "TagAccess" ON "Tag"."Text" like '"TagAccess"."TagPath"%'
When the correct SQL would be
SELECT "Tag"."Id", "Tag"."Text", "Tag"."Type", "Tag"."Comment"
FROM "Tag" INNER JOIN "TagAccess" ON "Tag"."Text" like CONCAT("TagAccess"."TagPath",%)
or
SELECT "Tag"."Id", "Tag"."Text", "Tag"."Type", "Tag"."Comment"
FROM "Tag" INNER JOIN "TagAccess" ON "Tag"."Text" like CONCAT("TagAccess"."TagPath",'%')
SELECT "Tag"."Id", "Tag"."Text", "Tag"."Type", "Tag"."Comment"
FROM "Tag" INNER JOIN "TagAccess" ON "Tag"."Text" like "TagAccess"."TagPath"+'%'
Would this be possible to get fixed?
I don’t think the classes are necessary for you in this case, but I’m joining on the column called Text:
public class Tag {
public string Text { get;set; } // /tag/looks/like/this
}
public class TagAccess {
public string TagPath { get;set; } // tag/looks/
// of course more, e.g. userid or something
}