public virtual void Delete() { var tableName = RowDataGatewayHelper.GetTableName(GetType()); dbQuery.ExecuteCommand($"DELETE FROM {tableName} WHERE {nameof(Id)} = @{nameof(Id)}", new SqlParameter { ParameterName = $"@{nameof(Id)}", Value = Id }); }
public virtual void Save() { var properties = GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(it => it.Name != nameof(Id)); var parameters = properties .Select(it => new SqlParameter { ParameterName = $"@{it.Name}", Value = it.GetValue(this, null) }); var tableName = RowDataGatewayHelper.GetTableName(GetType()); var propertiesString = string.Join(", ", properties.Select(it => it.Name)); var parametersString = string.Join(", ", parameters.Select(it => it.ParameterName)); dbQuery.ExecuteCommand($"INSERT INTO {tableName}({propertiesString}) VALUES({parametersString})", parameters.ToArray()); }