为什么我的Linq查询对SQLite不返回所有表字段值

本文关键字:字段 返回 Linq 我的 查询 SQLite 为什么 | 更新日期: 2023-09-27 17:54:28

我正在用SQLite构建一个WinRT应用程序。

我在c#代码中运行以下方法,以便从表ProductSubCategory中检索具有相等父ID的所有列

我正在使用最新版本的SQLite。. Net和SQLITE.NET.ASync

public async Task<IEnumerable<ProductSubCategory>> GetProductSubCategoryAsync(int ParentCategoryId)
{
    List<ProductSubCategory> lst = new List<ProductSubCategory>();
    var DBconn = await _sqliteService.OpenSQLiteConnection();
    {
        //retrive test data
        lst = await DBconn.Table<ProductSubCategory>().Where(c=>c.ParentSubCategoryId==ParentCategoryId).ToListAsync();
    }
    return lst;
}

类定义:

public class ProductCategory:ObservableObject
{
    [PrimaryKey]
    public int ProductCategoryId { get; set; }
    public string Name { get; set; }
    public string RowGuid { get; set; }
    public DateTime ModifiedDate { get; set; }
}

当代码执行时,它根据过滤器返回正确数量的记录,但不是所有返回字段值都被返回。

例如,我的所有INT类型的表字段以及主键都不会在我的对象中更新。

有什么原因和解决方案让它工作吗?我需要检索所有这些列数据。

为什么我的Linq查询对SQLite不返回所有表字段值

我设法找出了问题。我的表数据库列字段没有返回数据命名为ProductCategoryID我的对象名称为ProductCategoryID

这意味着当从数据库中获取字段时,字段名是区分大小写的,但奇怪的是,如果您插入数据,它们不是。

我只是将我的表字段名重命名为ProductCategoryID,现在我得到了正确的数据