AutoQuery AddCondition

I need to query a field and a string list for the same value, I started creating a custom search method but I can’t figure out how to add another query parameter, I tried using .AddCondition on my MemoryDataSource to no avail.

How do I add another condition or query after I call:

var q = AutoQuery.CreateQuery(query, Request, db);

Thanks

CreateQuery returns an OrmLite typed SqlExpression<Model> which you can further modify with your own custom conditions, e.g:

var q = AutoQuery.CreateQuery(query, Request, db);
q.Where(x => x.Field == value)
 .And(x => x.Field2 == value2);

Thanks Mythz but I am using IAutoQueryData which doesn’t provide that type, “db” is a MemoryDataSource.

Should this work out of the box? meaning the Search endpoints can inspect lists within a record?

This is what I have so far but it doesn’t work, ProxyAddresses is List[string] and I would need to perform a case insensitive search on it.

 public object Any(SearchWindowsUsers query)
        {
            var windowsUsers = WindowsUserManagementUtilities.GetWindowsUsers(false, true);
            var db = new MemoryDataSource<WindowsUser>(windowsUsers, query, Request);
            var q = AutoQuery.CreateQuery(query, Request, db);

            if (!string.IsNullOrWhiteSpace(query.Email))
            {
                var field = typeof(WindowsUser).GetProperty(nameof(WindowsUser.ProxyAddresses));
                
                q.AddCondition(QueryTerm.Or, field, InCollectionCondition.Instance, query.Email);
            }

            var users = AutoQuery.Execute(query, q, Request, db);

            return users;
        }
}

Do I have any other options?

Thanks

No my example only works with AutoQuery RDBMS.

Yeah adding a condition should work, but it wont do a case insensitive match, you should be able to do a custom condition that does it with:

public class CaseInsensitiveInCollectionCondition : QueryCondition, IQueryMultiple
{
    public static CaseInsensitiveInCollectionCondition Instance = new();

    public override string Alias => ConditionAlias.In;

    public override bool Match(object a, object b)
    {
        var bValues = b as IEnumerable;
        if (bValues == null)
            return new CaseInsensitiveEqualCondition().Match(a, b);
        foreach (var item in bValues)
        {
            if (new CaseInsensitiveEqualCondition().Match(a, item))
                return true;
        }
        return false;
    }
}

Otherwise you can always apply an in memory filter after query is executed.

That custom condition did the trick, thanks, I will assume that this behavior doesn’t work out of the box.

Lastly, how do I get the cache from Redis?

I have it setup to hydrate the cache in global.asax via:
return ctx.ServiceSource(new GetWindowsUsers(), HostContext.Cache, TimeSpan.FromHours(20));

If I try var windowsUser = Cache.Get(“aqd:/users/windows*”); it returns null…

Can the cache return the deserialized objects?

If you don’t specify a cacheKey on the 4th argument it uses the GET Url for the request which varies depending on the Request, you can search for aqd* keys on your Redis Instance to find the cache keys used.