user390480
user390480

Reputation: 1665

orderby not found error in LINQ to Entities

I have a class library that I use to hold the Entity Framework Data Model for my database. For testing purposes I created a class in the library named test.cs and added this code just to see if everything is working:

        var db = new EmailTestEntities();

        var x = from p in db.Emails
                orderby p.Created
                where p.EmailRouteID == 4
                select new {p.ID, p.MessageDate};

        foreach (var y in x)
        {
            var z = y.ID;
        }

Every thing works so I added the exact same code to my web application which has a reference to my library and a using statement for the reference.

However, I get the following error:

Could not find an implementation of the query pattern for source type 'System.Data.Objects.ObjectSet`1<EmailTestLibrary.Email>'.  'OrderBy' not found.

Why does the code work in the library but not in my web code?

Thanks!

Upvotes: 2

Views: 2170

Answers (4)

Sujay Paranjape
Sujay Paranjape

Reputation: 11

I had a similar issue.. using System.Linq fixed this for me

Upvotes: 0

Raja
Raja

Reputation: 3618

Please try this:

var x = from p in db.Emails                
                where p.EmailRouteID == 4
                orderby p.Created
                select new {p.ID, p.MessageDate};

HTH

Upvotes: 0

sambomartin
sambomartin

Reputation: 6813

You need to make sure you've referenced System.Data.Entity

HTH

Upvotes: 4

Priyank
Priyank

Reputation: 10623

Did you add using System.Linq;

Upvotes: 6

Related Questions