I am trying to change a few fields on an autoquery to query using or (it is a search box that is searching many fields). This doesn't seem to work although according to the documentation it should.
public class PropertyGet : QueryDb<DomainModel.Property>
{
[QueryDbField(Term=QueryTerm.Or)]
public string NameContains { get; set; }
[QueryDbField(Term=QueryTerm.Or)]
public string CityContains {get;set;}
}
However this does:
[QueryDb(QueryTerm.Or)]
public class PropertyGet : QueryDb<DomainModel.Property>
{
public string NameContains { get; set; }
public string CityContains {get;set;}
}
Changing Querying Behavior
By default queries act like a filter and every condition is combined with AND boolean term to further filter the result-set. This can be changed to use an OR at the field-level by specifying Term=QueryTerm.Or modifier, e.g:
[QueryDbField(Term=QueryTerm.Or)] public string LastName { get; set; }
How can I do a field level Or query?
The issue is due to using a [QueryDbField]
that relies on an implicit convention like "%Contains":
public class PropertyGet : QueryDb<DomainModel.Property>
{
[QueryDbField(Term=QueryTerm.Or)]
public string NameContains { get; set; }
[QueryDbField(Term=QueryTerm.Or)]
public string CityContains {get;set;}
}
Where when using [QueryDbField]
you would override the implicit convention. I've changed the behavior in this commit where it now merges the behavior of both [QueryDbField]
and the matching implicit convention so your query should now work as expected.
This change is available from v4.5.7+ that's now available on MyGet.