Xamarin 无法编译:参数 System.Collections.Generic.List`1[T] queryArgs

问题描述

我在查询 sqlite Xamarin 时遇到问题

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

报错过程如下:

我填充变量 nuevoRegistro:

enter image description here

dataService.InsertOrUpdate<PointOfSaleDTODBModel>(nuevoRegistro);

我的模型 PointOfSaleDTODBModel:

enter image description here

调用方法并将变量 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);
    }

得到的错误是下一个

enter image description here

错误文本:

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

任何帮助,谢谢

解决方法

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

  1. 使用 SQLiteAsyncConnection 而不是 SQLiteConnection ,refer to official docs

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

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...