Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# IQueryable Lambda表达式中的Orderby_C#_Linq_Entity Framework_Linq To Sql_Visual Studio Lightswitch - Fatal编程技术网

C# IQueryable Lambda表达式中的Orderby

C# IQueryable Lambda表达式中的Orderby,c#,linq,entity-framework,linq-to-sql,visual-studio-lightswitch,C#,Linq,Entity Framework,Linq To Sql,Visual Studio Lightswitch,我在跟随EF lambda表达式时遇到问题 partial void StatusCallBackRequired_PreprocessQuery(ref IQueryable<PatientsTelephoneFollowupDetail> query) { var newList = PatientsTelephoneFollowupDetails.OrderBy(x => x.Id).ToList(); query = query.Where(p =>

我在跟随EF lambda表达式时遇到问题

partial void StatusCallBackRequired_PreprocessQuery(ref IQueryable<PatientsTelephoneFollowupDetail> query)
{
    var newList = PatientsTelephoneFollowupDetails.OrderBy(x => x.Id).ToList();
    query = query.Where(p => p.PatientsMasterItem.PatientsTelephoneFollowupDetail.OrderByDescending(c => c.Id).FirstOrDefault(c => c.Status == "7") != null);
 }
错误是:

“Microsoft.LightSwitch.IORDedataServiceQueryable”不包含“ToList”的定义,并且找不到接受类型为“Microsoft.LightSwitch.IORDedataServiceQueryable”的第一个参数的扩展方法“ToList”。是否缺少using指令或程序集引用

我已经包括system.linq名称空间

编辑:基于D Stanley代码的结果

下面可以找到示例数据,我希望检索突出显示的记录

然而,电流输出是


将query更改为query.select只返回一条记录,但它是错误的记录

有两件事需要尝试:

转换为IEnumerable:

暴力:

var newList = new List<PatientsTelephoneFollowupDetail>();
foreach(var item in PatientsTelephoneFollowupDetails.OrderBy(x => x.Id))
    newList.Add(item);

您需要找到此类型的定义:Microsoft.LightSwitch.IORDedDataServiceQueryable

找到后,请确认:

它实现了IEnumerable吗?如果是这样,您的代码将无法访问。您说您使用的是System.Linq,所以请确保您的项目引用的是System.Core.dll

如果不是,它是否实现IEnumerable?如果是这样,您可以编写一个foreach循环,并将每个项添加到您创建的列表中


如果没有,请检查属性。通常有一些方法可以找到可以编写循环的对象。

是否重新构建它以确保没有看到过时的编译器错误?是否确定System.Linq有IORDedataServiceQueryable的扩展方法?当我搜索IORDedataServiceQueryable时,唯一出现的链接就是这个问题。我甚至不能研究这种类型,看看Linq是否为它提供了扩展方法。只是出于兴趣,为什么你要删除newList而不使用它?什么是Microsoft.LightSwitch.IORDedataServiceQueryable?它是可数的吗?或者,它是否有任何扩展方法ToList?如果是,则必须使用包含extends方法的名称空间。我认为preprocessquery函数只支持Iqueryable。是否有其他方法可以使用IQueryable而不是IEnumerable实现相同的功能?我正在使用LightSwitch,请参阅上的这篇文章以了解更多信息。尝试了第一个,没有编译错误,但在执行此查询时应用程序崩溃,出现以下错误无法转换类型的对象“Microsoft.LightSwitch.ServerGenerated.Implementation.QueryImplementation1[LightSwitchApplication.PatientsTelephoneFollowDetail]”输入“System.Collections.Generic.IEnumerable1[LightSwitchApplication.PatientsTelephoneFollowDetail]“.2nd one给了我以下错误错误1“System.Collections.Generic.List.ListSystem.Collections.Generic.IEnumerable”的最佳重载方法匹配有一些无效参数错误2参数1:无法从“Microsoft.LightSwitch.IORDedataServiceQueryable”转换为“System.Collections.Generic.IEnumerable”,我认为预处理查询函数仅支持Iqueryable。我仍然不理解EF、ADO.NET、LINQtoSQL etcIQueryable派生自IEnumerable之间的区别,但显然LightSwitch也没有实现IEnumerable。我编辑了我的答案,为您提供了另外两个选项。IEnumerable.Cast似乎有效。然而,结果并不像我预期的那样。可能是因为没有使用列表变量?如何将已排序的新列表应用到查询中?
var newList = new List<PatientsTelephoneFollowupDetail>(PatientsTelephoneFollowupDetails.OrderBy(x => x.Id)));
var newList = new List<PatientsTelephoneFollowupDetail>(
    PatientsTelephoneFollowupDetails.OrderBy(x => x.Id)
        .Cast<PatientsTelephoneFollowupDetail>()
    );
var newList = new List<PatientsTelephoneFollowupDetail>();
foreach(var item in PatientsTelephoneFollowupDetails.OrderBy(x => x.Id))
    newList.Add(item);