C# linq2db“;无法转换为sql";错误
我使用的Linq2db具有自定义的服务器端专用功能:C# linq2db“;无法转换为sql";错误,c#,linq,linq2db,C#,Linq,Linq2db,我使用的Linq2db具有自定义的服务器端专用功能: [Sql.Function(Name = "UniqueValue", ServerSideOnly = true)] public static int? UniqueValue( Expression<Func<ModelClass, string>> arg) { throw new NotSupportedException(); } [SQLiteFunction(Name = "U
[Sql.Function(Name = "UniqueValue", ServerSideOnly = true)]
public static int? UniqueValue( Expression<Func<ModelClass, string>> arg) {
throw new NotSupportedException();
}
[SQLiteFunction(Name = "UniqueValue", Arguments = 1, FuncType = FunctionType.Aggregate)]
public class UniqueValue : SQLiteFunction {
public override void Step(object[] args, int stepNumber, ref object contextData) {
}
public override object Final(object contextData) {
return null;
}
}
然后我得到“row=>row.field2”无法转换为SQL。运行时出现错误
我使用SqlLite作为数据库,以下是自定义函数:
[Sql.Function(Name = "UniqueValue", ServerSideOnly = true)]
public static int? UniqueValue( Expression<Func<ModelClass, string>> arg) {
throw new NotSupportedException();
}
[SQLiteFunction(Name = "UniqueValue", Arguments = 1, FuncType = FunctionType.Aggregate)]
public class UniqueValue : SQLiteFunction {
public override void Step(object[] args, int stepNumber, ref object contextData) {
}
public override object Final(object contextData) {
return null;
}
}
有人知道如何使自定义的仅服务器端函数与分组一起工作吗?在1.9.0版中添加了对linq2db中自定义聚合函数的支持。您需要将函数定义为自定义聚合,如下所示:
[Sql.Function("UniqueValue", ServerSideOnly = true, IsAggregate = true, ArgIndices = new[]{0})]
public static TResult UniqueValue<TSource, TResult>(this IEnumerable<TSource> src, Expression<Func<TSource, TResult>> value)
=> throw new NotSupportedException();
我怀疑服务器函数是否接受lambda(或等效值)作为参数。它可能只是一个
字符串
。我只使用lambda,因为我不知道如何将列名传递给我的唯一函数,因为它是组。我希望能够使用类似“选择UniqueValue(columnName)”的东西,数据库函数的签名是什么?@Gert Arnold:请查看更新的描述