【问题标题】:Xamarin Cannot compile: Parameter System.Collections.Generic.List`1[T] queryArgsXamarin 无法编译:参数 System.Collections.Generic.List`1[T] queryArgs
【发布时间】:2021-09-06 06:34:42
【问题描述】:

我对 SQLite Xamarin 的查询有疑问

我已经安装了sqlite-net-pcl 1.7.335SQLiteNetExtensions 2.0.0

报错的过程如下:

我填充变量 nuevoRegistro:

dataService.InsertOrUpdate<PointOfSaleDTODBModel>(nuevoRegistro);

我的模型 PointOfSaleDTODBModel:

我调用该方法并将变量 nuevoRegistro 发送给它

    public T InsertOrUpdate<T>(T model) where T : class, new()
    {
        try
        {
            var oldRecord = DataAccess.GetInstance().Find<T>(model.GetHashCode(), false);
            if (oldRecord != null)
            {
                DataAccess.GetInstance().Update(model);
            }
            else
            {
                DataAccess.GetInstance().Insert(model);
            }

            return model;
        }
        catch (Exception ex)
        {
            ex.ToString();
            return model;
        }
    }

这一步是我有问题的地方

    public T Find<T>(int pk, bool WithChildren) where T : class, new()
    {
        return connection.Table<T>().FirstOrDefault(n => n.GetHashCode() == pk);
    }

得到的错误是下一个:

错误文本:

  • “无法编译:参数”
  • at SQLite.TableQuery1[T].CompileExpr (System.Linq.Expressions.Expression expr, System.Collections.Generic.List1[T] queryArgs) [0x00b16] in &lt;d1788edcec634c19b907698bb77ed371&gt;:0 \n at SQLite.TableQuery1[T].CompileExpr (System.Linq.Expressions.Expression expr, System.Collections.Generic .List1[T] queryArgs) [0x001fb] in &lt;d1788edcec634c19b907698bb77ed371&gt;:0 \n at SQLite.TableQuery1[T].CompileExpr (System.Linq.Expressions.Expression expr, System.Collections.Generic.List1[T] queryArgs) [0x0009d] in &lt;d1788edcec634c19b907698bb77ed371&gt;:0 \n at SQLite.TableQuery1[T].GenerateCommand (System.String selectionList) [0x0005f] in :0 \ n 在 SQLite.TableQuery1[T].ToList () [0x00000] in &lt;d1788edcec634c19b907698bb77ed371&gt;:0 \n at SQLite.TableQuery1[T].FirstOrDefault () [0x00007] in :0 \n SQLite.TableQuery1[T].FirstOrDefault (System.Linq.Expressions.Expression1[TDelegate] predExpr) [0x00007] in :0 \n 在 IDS.Helpers。 DataAccess.Find[T] (System.Int32 pk, System.Boolean WithChildren) [0x0000e] 在 /Users/ingeneo/Documents/workspace/Xamarin/dms-mobile/dms-xamarin/IDS-only-login/IDS/Helpers/ DataAccess.cs:120 \n 在 /Users/ingeneo/Documents/workspace/Xamarin/dms-mobile/dms-xamarin/IDS-only-login 中的 IDS.Services.DataService.InsertOrUpdate[T](T 模型)[0x00002] /IDS/Services/DataService.cs:54`

任何帮助,谢谢你

【问题讨论】:

  • 请不要将代码或错误作为图片发布

标签: xamarin sqlite-net-extensions sqlite-net-pcl


【解决方案1】:

这里有一些对你的代码的建议,它可能会解决问题。

  1. 使用 SQLiteAsyncConnection 代替 SQLiteConnection refer to official docs

  2. 使用Id 而不是HashCode 来获取数据。

    Database.Table<TodoItem>().Where(i => i.ID == id).FirstOrDefaultAsync();      
    

【讨论】:

    猜你喜欢
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多