CodeLiturgy.Dashboard/CodeLiturgy.Views/Templates/GetOneTemplate.csx

17 lines
679 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>
2022-09-06 01:37:52 +03:00
/// <returns>A bool if the first occurrence of {returnTypeName} is returned.</returns>
2022-09-08 06:15:44 +03:00
public static (bool, {returnTypeFullName}) Get{entityTypeName}With (this {contextFullName} dbContext,
Expression<Func<{returnTypeFullName},bool>> with)
2022-09-06 00:42:45 +03:00
{
var {findEntityVarName} =
dbContext.{propertyName}
.Select(x => new {returnTypeFullName}(x))
.FirstOrDefault(with);
return ({findEntityVarName} != null, {findEntityVarName});
}