I am trying to implement a method to retrieve all the rows in a table, ordered by ID descending.
This is the code:
public IEnumerable<T> GetItemsDescending<T>() where T : IBusinessEntity, new()
{
lock (locker)
{
return Table<T>().Select(i => i).OrderByDescending(xx => xx.ID).ToList();
}
}
This looks like it should work, but I'm getting an error I don't understand:
"Order By does not support: xx => Convert(xx).ID"
from the following SQLite method:
private TableQuery<T> AddOrderBy<U>(Expression<Func<T, U>> orderExpr, bool asc)
{
if (orderExpr.NodeType == ExpressionType.Lambda)
{
var lambda = (LambdaExpression)orderExpr;
MemberExpression mem = null;
var unary = lambda.Body as UnaryExpression;
if (unary != null && unary.NodeType == ExpressionType.Convert)
{
mem = unary.Operand as MemberExpression;
}
else
{
mem = lambda.Body as MemberExpression;
}
if (mem != null && (mem.Expression.NodeType == ExpressionType.Parameter))
{
var q = Clone<T>();
if (q._orderBys == null)
{
q._orderBys = new List<Ordering>();
}
q._orderBys.Add(new Ordering
{
ColumnName = Table.FindColumnWithPropertyName(mem.Member.Name).Name,
Ascending = asc
});
return q;
}
else
{
throw new NotSupportedException("Order By does not support: " + orderExpr);
}
}
else
{
throw new NotSupportedException("Must be a predicate");
}
}
as requested: The PanelLog
class:
public class PanelLog : IBusinessEntity
{
public PanelLog()
{
}
[PrimaryKey, AutoIncrement]
public int ID { get; set; }
public uint Sequence { get; set; }
public DateTime Time { get; set; }
public string Message { get; set; }
public bool Alarm { get; set; }
}