LINQ to Entities中找不到orderby错误 [英] orderby not found error in LINQ to Entities

查看:58
本文介绍了LINQ to Entities中找不到orderby错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类库,用于保存数据库的实体框架数据模型.为了进行测试,我在库中创建了一个名为test.cs的类,并添加了以下代码以查看是否一切正常:

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

一切正常,因此我向Web应用程序添加了完全相同的代码,该代码具有对我的库的引用以及对该引用的using语句.

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.

但是,出现以下错误:

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

为什么代码在库中有效但在我的Web代码中无效?

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

谢谢!

推荐答案

您需要确保已引用System.Data.Entity

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

HTH

这篇关于LINQ to Entities中找不到orderby错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆