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

16 lines
815 B
Plaintext
Raw Normal View History

2022-09-05 05:58:37 +03:00
/// <summary>
2022-09-06 00:42:45 +03:00
/// Gets the first result in the table, and returns a projection of <see cref="{returnTypeFullName}"></see>
2022-09-05 05:58:37 +03:00
/// </summary>
/// <param name="dbContext">The database context.</param>
2022-09-06 01:37:52 +03:00
/// <param name="{byParamVarName}">By {byParamPropertyName} parameter type.</param>
2022-09-06 00:42:45 +03:00
/// <returns>A bool if the result is successfull, and the first occurrence of {entityTypeName}> </returns>
2022-09-05 05:58:37 +03:00
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});
}