繁体   English   中英

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

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

我在Xamarin Forms应用程序的sqlite数据库中有表,其中存储了大约12000个项目。 当我尝试通过以下查询仅返回一列时,得到了一个包含所有12000值的列表,但列表的条目为空。

该类的代码:

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

我用以下行查询表:

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

所以结果不是我所期望的。 我得到了包含12000个项目的完整列表,但每个项目都是NULL。 为什么?

图片来自调试...

如果我使用另一个查询,例如以下查询,它将按预期工作。

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

似乎在SQLite-net中执行select时出错,因此调用_Conn.Table<T>().ToList() ,然后调用select .Select(...) _Conn.Table<T>().ToList() sqlite-net问题

暂无
暂无

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

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