Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet'

c# entity-framework linq

Question

For the first time, I'm utilizing Entity Framework, but things don't appear to be going as planned.

I've got this code:

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;

public static class QueryClass
{
    public static void Query()
    {
        using (var context = new MyDbEntities())
        {
            DbSet<MyTable> set = context.Tables;
            var query = from val in set select value; 

        }
    }
}

I receive the following error on the query line (just where the "set" variable is underlined in red):

Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet'.'Select' not found. Missing a reference or an using directive for 'System.Linq'

MyDbEntities is generated automatically by Entity Framework using a database-first methodology,context.Tables is aDbSet , therefore it ought to be able to utilize Linq, which was added via theusing directive. In this class, I discover the following to help prevent errors:

public virtual DbSet<MyTable> Tables { get; set; }

What am I missing to complete the task?select work?

I'm grateful.

1
23
8/10/2015 11:22:50 AM

Accepted Answer

You must include a reference to the system. Data.Linq

System.Data.Linq is unique to LINQ-SQL (DataContext, etc)

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Linq;
using System.Linq;

public static class QueryClass
{
    public static void Query()
    {
        using (var context = new MyDbEntities())
        {

            IQueryable<MyTable> qTable= from t in context.Tables
                                        select t; // can you confirm if your context has Tables or MyTables?
            Console.WriteLine("Table Names:");
            foreach (var t in qTable)
            {
                Console.WriteLine(t.Name);//put the relevant property instead of Name
            }
        }
     }
}
36
7/6/2015 11:31:07 AM

Popular Answer

Just inserted a citationusing System.Linq; and performed well, as was already indicated,



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow