0

I use a Windows phone 8, MVVM + SQL Server CE 3.5 database

In folder model I have a declaration of table <TblCollections>

In folder ViewModel have this code for getting the collection.

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;
        }
    }

I receive error on query.ToList();

Explicit construction of entity type "TblCollections" in query is not allowed

Why?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
John Brush
  • 177
  • 11
  • What's the issue in using 'from collection in db.TblCollections select collection' – gitesh.tyagi Feb 21 '14 at 10:17
  • I need to use it in this way because I make count in the select new. for example select new TblCollections { a = (string)collection.a, b = (int)collection.b, id = (int)collection.id, count= (int)collection.tblfiles.count(); }; – John Brush Feb 21 '14 at 10:36
  • try below anonymous class suggestion as you want few properties that might help. – gitesh.tyagi Feb 21 '14 at 10:49

1 Answers1

0

Do not specify class and Try this(Untested code):

IEnumerable<TblCollections> query = from collection in db.TblCollections
                        select new
                        {
                            a = (string)collection.a,
                            b = (int)collection.b,
                            id = (int)collection.id,
                        };
gitesh.tyagi
  • 2,271
  • 1
  • 14
  • 21