I want to convert below SQL query to linq query but I confused:
SELECT *
FROM dbo.Vahed
INNER JOIN dbo.VahedMahsol ON dbo.Vahed.VahedId = dbo.VahedMahsol.VahedId
RIGHT OUTER JOIN dbo.Mahsol ON dbo.VahedMahsol.MahsolId = dbo.Mahsol.MahsolId
I wrote this code:
vaheds =
(
from i in db.spGetVahedByWhatWhere(what, wherestr, int.Parse(whattype), new Guid(shahrid))
join gr in db.GorohSenfis on i.GorohSenfiId equals gr.GorohSenfiID
join ct in db.Contacts on i.VahedId equals ct.VahedId
join vm in db.VahedMahsols on i.VahedId equals vm.VahedId
select i
)
.ToList();
but i don’t know how to convert
RIGHT OUTER JOIN dbo.Mahsol ON dbo.VahedMahsol.MahsolId = dbo.Mahsol.MahsolId
to linq query.
First of all you can rewrite your SQL query to use a LEFT OUTER JOIN instead of a RIGHT OUTER JOIN (because this is easier to convert to LINQ):
Now you can convert the query above in LINQ like this:
I have no way of testing this, but I hope it works.