这是代码:
public IEnumerable<T> GetItemsDescending<T>() where T : IBusinessEntity,new() { lock (locker) { return table<T>().Select(i => i).OrderByDescending(xx => xx.ID).ToList(); } }
这看起来应该可行,但我收到一个我不明白的错误:
"Order By does not support: xx => Convert(xx).ID"
从以下sqlite方法:
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"); }}
按要求:PanelLog类:
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; }}解决方法 没有答案?
好吧,这就是我正在做的工作:
public static IEnumerable<PanelLog> GetPanelLogsDescendingsql(params object[] args){ return me.db.query<PanelLog>("select * from PanelLog ORDER BY ID DESC"); }总结
以上是内存溢出为你收集整理的如何通过SQLite.NET降序排序? OrderByDescending()给我错误:“Order By不支持:xx => Convert(xx).ID”全部内容,希望文章能够帮你解决如何通过SQLite.NET降序排序? OrderByDescending()给我错误:“Order By不支持:xx => Convert(xx).ID”所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)