Convert (xx) .ID" I am trying to...">

How to order descending with SQLite.NET? OrderByDescending () gives me an error: "Order By does not support: xx => Convert (xx) .ID"

I am trying to implement a method to retrieve all rows in a table, sorted in descending order by name.

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(); } } 

It seems like it should work, but I get an error message that 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: 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; } } 
+4
source share
1 answer

No answers?

Ok, this is what I do as a job:

 public static IEnumerable<PanelLog> GetPanelLogsDescendingSql(params object[] args) { return me.db.Query<PanelLog>("select * from PanelLog ORDER BY ID DESC"); } 
+4
source

Source: https://habr.com/ru/post/1486192/


All Articles