0

我使用的是 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”

为什么?

4

1 回答 1

0

不要指定类并试试这个(未经测试的代码):

IEnumerable<TblCollections> query = from collection in db.TblCollections
                        select new
                        {
                            a = (string)collection.a,
                            b = (int)collection.b,
                            id = (int)collection.id,
                        };
于 2014-02-21T10:45:21.417 回答