Autoquery Filter many to Many

I have been struggling to find a good way to filter in AQ across multiple tables.

Some stuff I have got working but it is a bit buggy. I made this a blog post as it is quite long as I try to explain what I am doing and why I need it and what doesn’t work.

If you could have a look I would appreciate it as took some time to create the sample code and try to explain my issue.

Many thanks

https://talktechnical.net/servicestack-autoquery-filtering-by-many-to-many-relationships/

Can you download the latest v5.7.1 on MyGet.

Your example highlighted an issue with Regex replacement when merging/rewritting params from multiple expressions where a Regex number pattern search doesn’t match when it’s the last expression in a string.

The result was that the params weren’t getting rewritten so that your subsequent queries were using the first param, it should now work as expected.

Thank Mythz, the fix makes it work with AND queries now.

I updated the article and project to try to mix AND and OR logic across multiple tables. The results I get are very close but I need to add the clauses inside a group but I can’t figure out how to do that with OrmLite.

Could you take a look please and let me know if it is possible?

Many thanks

AutoQuery is not going to be able add a filter to your custom query, you’d need to add it yourself if you want it within the same expression, e.g:

if (authorAuto.Params.Count > 0) 
    q.Or<Book>(x => x.Title.Contains("Frozen") && Sql.In(x.Id, authorAuto));

Are there any public methods I can use to convert the query parameters into sql? For example it would convert “SomeColumnContains=text” into “table”.“some_column” LIKE ‘%text%’.

If I could do that then I wont have to duplicate all logic for implicit conventions.

There’s no reusable public methods available, but the source code starts from AppendTypedQueries().