如何修复此 LINQ 错误
我期望的结果是:没有任何子项的记录列表,我的菜单表架构是:ID(长)、名称(字符串)、订单(int)、ParentID(长)
首先选择所有叶级子项身份证。获取除 ParentID 列中的值之外的所有 ID。然后通过在此处加入 leafID 来从菜单中进行选择
我的代码:
var leafMenuIDs = menus
.Select(m => m.ID)
.Except(menus.Select(m => m.ParentID).Distinct())
.Distinct();
this.ddlMenu.DataSource = from m in menus
join id in leafMenuIDs on m.ID equals id
select new { m.ID, m.Name };
我收到错误:除了运算符是:
System.collections.generic.IEnumberable
不包含“Except”的定义和最佳方法重载System.LINQ.queryable.Except
有一些无效参数。(System. LINQ.IQueryalbe 、System.collections.generic.IEnumberable )
请帮我修复这个错误。多谢
The Result as i expect here is : list of record that do not have any children, my Menu table schema is : ID (long), Name(string), Order(int), ParentID (long)
first select all the leaf level children IDs. Get all ID except the values in the ParentID column. And then do a select from menu by joining the leafIDs
here my code :
var leafMenuIDs = menus
.Select(m => m.ID)
.Except(menus.Select(m => m.ParentID).Distinct())
.Distinct();
this.ddlMenu.DataSource = from m in menus
join id in leafMenuIDs on m.ID equals id
select new { m.ID, m.Name };
i got a error : at Except operator is :
System.collections.generic.IEnumberable<long>
does not contains a definition for 'Except' and the best method overloadSystem.LINQ.queryable.Except<TSource>(System.LINQ.IQueryalbe<TSource>, System.collections.generic.IEnumberable<Tsource>)
has some invalid arguments .
please help me fix this error. thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样:
在这里,您选择了每个没有
ParentID
引用的menu
。为了回应 @mmix 的评论,这里是生成的 SQL(使用 Linqpad)
What about something like:
Here you are selected every
menu
that doesn't have aParentID
referring back to it.In response to comment by @mmix, here's the generated SQL (using Linqpad)
我认为这里的问题可能是
m=>m.ID
&m=>m.ParentID
存在冲突。尝试将其更改为
m=>m.ID
和x=>x.ParentID
(不同的 lambda 表达式名称)I think the problem here might be that
m=>m.ID
&m=>m.ParentID
are conflicting.Try changing it to
m=>m.ID
andx=>x.ParentID
(different lambda expression names)