diff --git a/BlueWest.Api/Context/Templates/GetListTemplate.csx b/BlueWest.Api/Context/Templates/GetListTemplate.csx index 32d5451..5eab601 100644 --- a/BlueWest.Api/Context/Templates/GetListTemplate.csx +++ b/BlueWest.Api/Context/Templates/GetListTemplate.csx @@ -6,7 +6,6 @@ /// How many {propertyName} to skip. /// How many {propertyName} to take. (Default = 50) /// Optional Order direction -/// Optional where predicate. /// Optional order by predicate. /// A bool if there's at least one record found and the resulting array. public static (bool, {returnTypeFullName}[]) Get{entityTypeName}{listPropertyName}(this {contextFullName} dbContext, {primaryKeyFullName} {primaryKeyVarName}, diff --git a/BlueWest.Api/Context/Templates/GetManyTemplate.csx b/BlueWest.Api/Context/Templates/GetManyTemplate.csx index dc71750..a617c50 100644 --- a/BlueWest.Api/Context/Templates/GetManyTemplate.csx +++ b/BlueWest.Api/Context/Templates/GetManyTemplate.csx @@ -12,19 +12,21 @@ public static (bool, {returnTypeFullName}[]) Get{propertyName}(this {contextFull Expression > where = null, Expression > orderBy = null) { + if (take > 200) take = 200; + var query = dbContext .{propertyName} .Select(x => new {returnTypeFullName}(x)); - - // limit take by 200 records - if (take > 200) take = 200; - query.Skip(skip).Take(take); - - if (where != null) query.Where(where); + .Skip(skip) + .Take(take); + + if (where != null) query = query.Where(where); + if(orderBy != null) { - if (orderDir == 1) query.OrderBy(orderBy); - else query.OrderByDescending(orderBy); + if (orderDir == 1) query = query.OrderBy(orderBy); + else query = query.OrderByDescending(orderBy); } + return (query.Any(), query.ToArray()); } \ No newline at end of file