开发者

orderby not found error in LINQ to Entities

开发者 https://www.devze.com 2023-03-04 13:18 出处:网络
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 everyth

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!


Did you add using System.Linq;


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

HTH


Please try this:

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

HTH


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号