我使用的是Windows Phone 8,MVVM + SQL Server CE 3.5数据库
在文件夹model
中,我有一个表<TblCollections>
在文件夹ViewModel
中有此代码用于获取集合。
public IEnumerable<TblCollections> GetTblCollections()
{
using (DbContext db = new DbContext(DbContext.ConnectionString))
{
var query = from collection in db.TblCollections
select new TblCollections
{
a = (string)collection.a,
b = (int)collection.b,
id = (int)collection.id,
};
IEnumerable<TblCollections> _TblCollections = query.ToList();
return _TblCollections;
}
}
我在query.ToList();
不允许在查询中明确构造实体类型“TblCollections”
为什么?
答案 0 :(得分:0)
不要指定类并尝试此(未经测试的代码):
IEnumerable<TblCollections> query = from collection in db.TblCollections
select new
{
a = (string)collection.a,
b = (int)collection.b,
id = (int)collection.id,
};