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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted Mar 16, 2015, 9:52 AM
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
VulpesPosted Mar 16, 2015, 8:21 AM
Manish Kumar ChoudharyPosted Mar 16, 2015, 7:54 AM
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
Vikram AgrawalPosted Mar 16, 2015, 7:50 AM
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