28 lines
1.2 KiB
C#
28 lines
1.2 KiB
C#
/// <summary>
|
|
/// Gets {propertyName}.
|
|
/// </summary>
|
|
/// <param name="dbContext">The database context.</param>
|
|
/// <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 the result is successful and has at least 1 occurrence of {propertyName}. </returns>
|
|
public static (bool, {returnTypeFullName}[]) Get{propertyName}(this {contextFullName} dbContext, int skip = 0, int take = 50, int orderDir = 1,
|
|
Expression <Func<{returnTypeFullName}, bool> > where = null,
|
|
Expression <Func<{returnTypeFullName}, object> > orderBy = null)
|
|
{
|
|
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);
|
|
if (orderDir == 1) query.OrderBy(orderBy);
|
|
else query.OrderByDescending(orderBy);
|
|
|
|
return (query.Any(), query.ToArray());
|
|
} |