Fix in templates

This commit is contained in:
CodeLiturgy 2022-09-09 04:44:33 +01:00
parent ad760cc1db
commit f46d20c1ea
2 changed files with 10 additions and 9 deletions

View File

@ -6,7 +6,6 @@
/// <param name="skip">How many {propertyName} to skip.</param>
/// <param name="take">How many {propertyName} to take. (Default = 50)</param>
/// <param name="orderDir">Optional Order direction</param>
/// <param name="where">Optional where predicate.</param>
/// <param name="orderBy">Optional order by predicate.</param>
/// <returns>A bool if there's at least one record found and the resulting array. </returns>
public static (bool, {returnTypeFullName}[]) Get{entityTypeName}{listPropertyName}(this {contextFullName} dbContext, {primaryKeyFullName} {primaryKeyVarName},

View File

@ -12,19 +12,21 @@ public static (bool, {returnTypeFullName}[]) Get{propertyName}(this {contextFull
Expression <Func<{returnTypeFullName}, bool> > where = null,
Expression <Func<{returnTypeFullName}, object> > 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());
}