CodeLiturgy.Dashboard/BlueWest.Api/Context/Templates/GetOneTemplate.csx

17 lines
690 B
Plaintext
Raw Normal View History

2022-09-06 00:42:45 +03:00
/// <summary>
/// Gets the first result following the query with a expression.
/// </summary>
/// <param name="dbContext">The database context.</param>
/// <param name="with">FirstOrDefault argument to pass.</param>
/// <returns>A bool if the result is successfull, and the first occurrence of {returnTypeName}</returns>
public static (bool, {returnTypeFullName}) Get{entityTypeName}With (this {contextFullName} dbContext, Expression<Func<{returnTypeFullName},bool>> with)
{
var {findEntityVarName} =
dbContext.{propertyName}
.Select(x => new {returnTypeFullName}(x))
.FirstOrDefault(with);
return ({findEntityVarName} != null, {findEntityVarName});
}