Hello All,
Want to change below sql query to Linq query :
select userid,deviceid from Users_Device where UserId in(select userid from Master_Contact where AddedUserId = 305)
pl help me.
Thanks.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vikram AgrawalRank #4,713 · 329 reputationPosted Mar 16, 2015, 3:50 AM EDT
Hi Dipesh,
you can try this
var innerQuery = from mc in Master_contact where mc.AddedUserId = 305 select mc.userid ;
var result = from ud in Users_Device where innerQuery.Contains(ud.Userid ) select ud.userid,ud.deviceid ;
thanks
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Mar 16, 2015, 3:54 AM EDT
Go through following link it will help you
https://msdn.microsoft.com/en-us/library/bb397678.aspx
http://stackoverflow.com/questions/2055254/how-to-write-a-linq-to-entities-query-with-list-in-a-where-condition
VulpesRank #55 · 29.2K reputationPosted Mar 16, 2015, 4:21 AM EDT
Posted Mar 16, 2015, 5:52 AM EDT
var query = (from ud in db.Users_Device where
(from mc in db.Master_Contact where (mc.AddedUserId == 305)) select mc.UserId).Contains(ud.UserId)
select ud.DeviceId).ToList();
Thanks for Reply