两条linq合并嵌套就出错

lovebaby 2015-05-21 02:17:05

//这样分成两步可以
var rootid = (from c in ctx.mf_ProductClass where c.ClassID == int.Parse(classid) select c.ParentPath).First().Split(',')[1];
var attlist = from p in ctx.View_mf_ProductAttList where p.ClassID == Convert.ToInt16(rootid) select p;
//这样合成一步就出错:无法识别的表达式节点: ArrayIndex
var attlist = from p in ctx.View_mf_ProductAttList where (from c in ctx.mf_ProductClass where c.ClassID == int.Parse(classid) select c.ParentPath).First().Split(',')[1].Contains(p.ClassID.ToString()) select p;
//这样也不行,还是同样的错误
var attlist = from p in ctx.View_mf_ProductAttList where p.ClassID == Convert.ToInt16((from c in ctx.mf_ProductClass where c.ClassID == int.Parse(classid) select c.ParentPath).First().Split(',')[1]) select p;
...全文
242 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
q107770540 2015-05-22
  • 打赏
  • 举报
回复
var attlist = from p in ctx.View_mf_ProductAttList
              let rootid= from c in ctx.mf_ProductClass.ToList()
                          where c.ClassID == Convert.ToInt32(classid) 
                          select c.ParentPath).First().Split(',')[1]
               where  p.ClassID == Convert.ToInt32(rootid) 
               select p;
q107770540 2015-05-22
  • 打赏
  • 举报
回复
不能转化一下思路?
var attlist = from p in ctx.View_mf_ProductAttList
              let rootid= from c in ctx.mf_ProductClass 
                          where c.ClassID == int.Parse(classid) 
                          select c.ParentPath).First()
               where (","+rootid+",").Contains(","+p.ClassID+",")
               select p;
moonwrite 2015-05-21
  • 打赏
  • 举报
回复
var whereQuery=from c in ctx.mf_ProductClass where c.ClassID == int.Parse(classid) select c.ParentPath).First().Split(',')[1].Contains(p.ClassID.ToString()) select p, var attlist = from p in ctx.View_mf_ProductAttList where whereQuery.Contain(p.ClassID) 可以写成2句,ef会在调用的时候 再把你合成一sql,看你对ef了解 where p.ClassID == Convert.ToInt16((from c in ctx 等于一个集会 怎么可能

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧