SS 6.8
Putting Term=QueryTerm.Or on a int[] causes the parameters to be passed as a string to the query, rather than as separate parameters
I have the following class
public class QueryActionItems : QueryDb<ActionItem>
{
public int? Id { get; set; }
[QueryDbField(Term=QueryTerm.Ensure)]
public bool? IsCompleted { get; set; }
[QueryDbField(Template = "{Field} BETWEEN {Value1} AND {Value2}",
Field="DateCreated", Term = QueryTerm.Ensure)]
public DateTime[] DateCreatedBetween { get; set; }
[QueryDbField(Term=QueryTerm.Or)]
public int? CreatedBy { get; set; }
[QueryDbField(Term=QueryTerm.Or)]
public int? Owner { get; set; }
[QueryDbField(Term=QueryTerm.Or)]
public int[]? Owners { get; set; }
[QueryDbField(Term=QueryTerm.Or)]
public int[]? CreatedBys { get; set; }
}
That will generate the following broken query has seen from the profiler:
SELECT TOP 5 “Id”, “Action”, “IsCompleted”, “Notes”, “Resolution”, “Owner”, “DateCreated”, “CreatedBy”, “DateModified”, “ModifiedBy”, “DateDeleted”, “DeletedBy” FROM “ActionItem” WHERE (“ActionItem”.“IsCompleted” = @1) AND “ActionItem”.“DateDeleted” IS NULL AND ((“ActionItem”.“Owner” = @2) OR (“ActionItem”.“CreatedBy” = @3)) ORDER BY “DateCreated” DESC
With the following parameters:
{
“@0”: “null”,
“@1”: false,
“@2”: “[163,217,158]”,
“@3”: “[163,217,158]”
}
If I comment out both Or terms on the class I see the following:
SELECT COUNT() "COUNT()" FROM “ActionItem” WHERE (“ActionItem”.“IsCompleted” = @1) AND “ActionItem”.“DateDeleted” IS NULL AND (“ActionItem”.“Owner” IN (@2,@3,@4) AND “ActionItem”.“CreatedBy” IN (@5,@6,@7))
With the following parameters
{
“@0”: “null”,
“@1”: false,
“@2”: 163,
“@3”: 217,
“@4”: 158,
“@5”: 163,
“@6”: 217,
“@7”: 158
}