开发者

"where in " clause in linq

below is my 开发者_如何学Gosql query

select * 
from test1View 
where test1ID in (select distinct(test2ID) from test2Result) 

I want this query in Linq please


You can do as below to achieve where in functionality in linq

   DataClassesDataContext db = new DataClassesDataContext();
        List<int> lstGroups = db.APP3_FRM2GRPs.Where(x => x.FGR_FRM_PKEY == Convert.ToInt32(ddlForms.SelectedValue)).Select(b => b.FGR_GRP_PKEY).ToList<int>();
        var qry = from item in db.APP3_GROUPs
                  where lstGroups.Contains(item.GRP_PKEY)
                  select item;


IQueryable<int> subQuery = db.Test2Result
  .Select(tr => tr.Test2Id)
  .Distinct();

IQueryable<Test1View> query = db.Test1View
  .Where(tv => subQuery.Contains(tv.Test1ID);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜