[英]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.