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

16 lines
887 B
Plaintext
Raw Normal View History

2022-09-05 05:58:37 +03:00
/// <summary>
/// Gets the first result in the table, and returns a projection of <see cref="{returnTypeFullName}"></see> .
/// </summary>
/// <param name="dbContext">The database context.</param>
/// <param name="{byParamVarName}">By {byParamPropertyName} <see cref="{byParamFullType}"></see></param>
/// <returns>A bool if the result is successfull, and the first occurrence of {entityTypeName} as a projection <see cref="{returnTypeFullName}"> </returns>
public static (bool, {returnTypeFullName}) GetOne{entityTypeName}By{byParamPropertyName} (this {contextFullName} dbContext, {byParamFullType} {byParamVarName})
{
var {findEntityVarName} = dbContext.{propertyName}
.Where(x => x.{byParamPropertyName} == {byParamVarName})
.Select(x => new {returnTypeFullName}(x))
.FirstOrDefault();
return ({findEntityVarName} != null, {findEntityVarName});
}