I am having two tables and I want data in such a manner that. I want to make this query in Linq. Can it be possible?
Table1
pkId SenderId ReceiverId
1 2 5
2 2 2
3 2 7
4 3 2
Table 2
pkTbl2Id fkId fkUserId
1 1 2
2 2 7
I want to fetch that records from table one which have
table1.SenderId == 2 || table1.ReceiverId == 2 && Table 2.fkId == Table1.pkId
the answer will be first records of First table i.e
1 2 5
I have used::
return DB.table1
.Where(x =>
x.receiverId == 2
|| x.senderID == 2
&& DB.table2.Any(y => y.fkid == x.pkid))
.Count();
var ll = from rs in DB.tblMessages
join mm in DB.tblLogs
on rs.pkMessageId equals mm.fkMessageId
where rs.fkReceiverUserId == UserId || rs.fkSenderUserId == UserId && mm.fkUserID == UserId
select rs;