CodeLiturgy.Dashboard/BlueWest.Domain/Templates/GetManyTemplate.csx

25 lines
1.0 KiB
Plaintext
Raw Normal View History

2022-09-06 00:42:45 +03:00
/// <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>
2022-09-09 06:26:16 +03:00
/// <returns>A bool if the result is successful and a projection of the first occurrence of {propertyName}. </returns>
2022-09-10 07:12:03 +03:00
public static (bool, System.Collections.Generic.List<{returnTypeFullName}>) Get{propertyName}(this {contextFullName} dbContext, int skip = 0, int take = 50, int orderDir = 1)
2022-09-06 00:42:45 +03:00
{
2022-09-09 06:44:33 +03:00
if (take > 200) take = 200;
2022-09-06 00:42:45 +03:00
var query = dbContext
.{propertyName}
2022-09-09 06:44:33 +03:00
.Skip(skip)
2022-09-10 07:12:03 +03:00
.Take(take)
.Select(x => new {returnTypeFullName}(x));
2022-09-09 06:44:33 +03:00
2022-09-10 07:12:03 +03:00
var result = query.ToList();
2022-09-09 06:44:33 +03:00
2022-09-10 07:12:03 +03:00
return (result.Any(), result);
2022-09-06 00:42:45 +03:00
}