简体   繁体   English

用linq查询sqlite表返回一个包含空项目的列表

[英]Querying sqlite table with linq returns a list with empty items

I have table in a sqlite database in a Xamarin Forms app with about 12000 items stored in it. 我在Xamarin Forms应用程序的sqlite数据库中有表,其中存储了大约12000个项目。 When I try to return only one column with the following query, I got a list with all 12000 values but the entries of the list are null. 当我尝试通过以下查询仅返回一列时,得到了一个包含所有12000值的列表,但列表的条目为空。

Code for the class: 该类的代码:

public class BaseModel
{
        private int? _PrimaryKey;
        private string _Code;
        private string _Name;

        [PrimaryKey, Required, NotNull]
        public int? PrimaryKey { get { return _PrimaryKey; } set { _PrimaryKey = value; } }

        public string Code { get { return _Code; } set { _Code = value; } }

        public string Name { get { return _Name; } set { _Name = value; } }
}

I to query the table with the following line: 我用以下行查询表:

internal T GetInsertItem<T>() where T : BaseModel, new()
{
    T item = new T();
    //...
    List<int?> items = new List<int?>(_Conn.Table<T>().Select(ac => ac.PrimaryKey));
    //...
    return item;
}

So the result is not what i expected. 所以结果不是我所期望的。 I got the full list with 12000 items but every item is NULL. 我得到了包含12000个项目的完整列表,但每个项目都是NULL。 Why? 为什么?

Image from the debugging ... 图片来自调试...

If I use another query like the following one, it works as I expected. 如果我使用另一个查询,例如以下查询,它将按预期工作。

List<T> items = new List<T>(_Conn.Table<T>().Where<T>(ac => ac.PrimaryKey > 1000));

It seems there is an error in the implementation of select in SQLite-net, so calling _Conn.Table<T>().ToList() and then the select .Select(...) helps. 似乎在SQLite-net中执行select时出错,因此调用_Conn.Table<T>().ToList() ,然后调用select .Select(...) _Conn.Table<T>().ToList() sqlite-net issues sqlite-net问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM