【发布时间】:2015-06-20 15:14:43
【问题描述】:
我正在使用 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 类型的表字段以及主键都不会在我的对象中更新。
有什么理由和解决方案让它发挥作用吗?我需要检索所有这些列数据。
这是否取决于创建字段的方式?
【问题讨论】:
-
请添加
ProductSubCategory的类定义。 -
productSubCategory 类定义存在相同的文件名和类型。我在上面的帖子中添加了定义。我需要在我的类字段中返回 PrimaryKey,但事实并非如此。有什么理由吗?
标签: c# linq sqlite windows-runtime sqlite-net