Auto Query and enum marked as Flag (bitwise operation)

Imagine to have the following enum:

[Flags]
public enum CompanyType
{
    Customer = 1,
    Supplier = 2,
    Owner = 4,
    Purchaser = 8,
    Resource = 16,
}

If the Company have more than a role in the system (e.g… Customer & Supplier), the CompanyType field in the Companies table assume the value equal to 3. When we want to retrieve a Customer we’d like auto query list all Companies where the fields CompanyType include (in the bit mask) the value 1 (eg. 1 and 3).

Is there a way with auto query to do that?

AutoQuery doesn’t have any notion of bitwise arithmetic embedded in it, but I’d expect you could create a custom adhoc query to be able to use Custom SQL with your arguments, I’m assuming something like:

[QueryDbField(Template = "{Value} & {Field} = {Value}", 
            Field = "CompanyType")]
public int HasRole { get; set; }

Thanks a lot, it works as expected

1 Like