We have some code that tries to build a SQL Expression using OrmLite.
For some reason it is failing when it gets to our extension method WithChangedColumns<T>
where it fails at the following line expression.Where(x => x.UpdateColumns.ContainsAny(formatted)
with the following exception:
variable 'x' of type 'Deltas.PROD' referenced from scope '', but it is not defined
public class QueryableService : Service
{
public object Any(PRODRequest request)
{
return new PRODResponse
{
Records = Db.DeltaQuery<PROD>(request)
};
}
}
public static class SqlExpressionExtensions
{
public static T[] DeltaQuery<T>(
this IDbConnection connection,
AbstractDeltaRequest request) where T : IAuditRecord =>
connection.Select(connection.From<T>()
.WithActionType(request.ActionType)
.FromAuditDate(request.EffectiveFrom)
.WithChangedColumns(request.Columns)
.Ordered(request.Direction)
.Paged(request)).ToArray();
public static SqlExpression<T> WithChangedColumns<T>(this SqlExpression<T> expression, string[] updatedColumns) where T : IAuditRecord
{
var formatted = updatedColumns?.Select(c => $$"[{c}]").ToArray();
return formatted.IsNullOrEmpty()
? expression : expression.Where(x => x.UpdateColumns.ContainsAny(formatted));
}
}
public interface IAuditRecord
{
string UpdateColumns { get; set; }
}
public class PROD : IAuditRecord
{
public string UpdateColumns { get; set; }
}