asp.net – LINQ:不支持查询运算符’ElementAtOrDefault’
发布时间:2020-11-14 09:01:52 所属栏目:asp.Net 来源:互联网
导读:为什么以下代码会产生错误? The query operator ‘ElementAtOrDefault’ is not supported Dim Im = (From view In Db.Views Where _ view.Pass = txtCode.Text _ Select New With {.Id = view.UniqueID.
为什么以下代码会产生错误?
Dim Im = (From view In Db.Views Where _ view.Pass = txtCode.Text _ Select New With {.Id = view.UniqueID.ToString}_ ).Distinct Response.Redirect("~/test.aspx?x=" & Im(0).Id) 有没有办法在不使用FirstOrDefault选项的情况下修复它? 更新:这是StackTrace at System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) at System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc) at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) at System.Data.Linq.SqlClient.QueryConverter.ConvertOuter(Expression node) at System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query,SqlNodeAnnotations annotations) at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression) at System.Linq.Queryable.ElementAtOrDefault[TSource](IQueryable`1 source,Int32 index) at Login.btnLogin_Click(Object sender,EventArgs e) in D:ProjectsMemoriaLogin.aspx.vb:line 14 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) 解决方法您需要做的是将.ToList()添加到查询的末尾.这应该工作:Dim Im = (From view In Db.Views Where _ view.Pass = txtCode.Text _ Select New With {.Id = view.UniqueID.ToString}_ ).Distinct.ToList() Response.Redirect("~/test.aspx?x=" & Im(0).Id) 如果没有.ToList(),查询只返回一个DataQuery(Of T)而不是List(Of T).添加ToList调用有两个作用: >强制查询立即执行,和 希望有所帮助! (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET AJAX中的$create函数是什么?
- asp.net-mvc – 如何将复选框绑定到视图模型的List属性?
- 中国网通新版400电话 - 企业直线
- asp.net-mvc – ASP.NET MVC中的Windows Live ID
- asp.net – 如何接收JSON作为MVC 5操作方法参数
- asp.net-mvc – ACS安装,但MVC 4.0应用程序仍然重定向,无法
- asp.net-mvc – 如何正确识别vs2008版本级别?
- asp.net – Visual Studio 2010图表控件:使Y轴成为整数值,
- asp.net-mvc – ASP.NET MVC视图模型的最佳做法
- 部署 – kestrel-hellomvc.service:步骤USER产生失败/usr/
推荐文章
站长推荐
- asp.net – 如何扩展aspnet成员身份验证表?
- asp.net-mvc-3 – 使用@ Html.Raw有风险吗?
- asp.net-mvc – 在ASP.NET MVC中获取当前操作/控
- asp.net-mvc – 发现MVC项目中是否使用views / p
- asp.net-mvc – ASP.NET MVC模型/ ViewModel验证
- .Net core Blazor自定义日志提供器实现实时日志查
- ASP.NET性能优化之局部缓存分析
- asp.net – MS Chart for .NET预定义调色板颜色列
- 如何在ASP.NET和C#中加载下拉列表?
- asp.net-mvc – 如何在asp.net mvc中处理分页?
热点阅读