Convert(xx).ID"-6ren"> Convert(xx).ID"-我正在尝试实现一种方法来检索表中的所有行,按 ID 降序排序。 这是代码: public IEnumerable GetItemsDescending() where T : IBusines-6ren">
gpt4 book ai didi

sqlite - 如何使用 SQLite.NET 按降序排序? OrderByDescending() 给我错误 : "Order By does not support: xx => Convert(xx).ID"

转载 作者:行者123 更新时间:2023-12-03 16:16:52 28 4
gpt4 key购买 nike

我正在尝试实现一种方法来检索表中的所有行,按 ID 降序排序。

这是代码:

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

最佳答案

没有答案?

好的,这就是我正在做的工作:

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

关于sqlite - 如何使用 SQLite.NET 按降序排序? OrderByDescending() 给我错误 : "Order By does not support: xx => Convert(xx).ID",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17104378/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com