LINQ Inner Join
1537
15-Mar-2016
We want to use Inner Join in linq .how to write inner join query please help me.
Anonymous User
15-Mar-2016Join. This is a keyword in LINQ. As with other query languages (such as SQL) joining matches every element in two collections based on some condition.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace ForumMVC.Controllers
{
public class HomeController : Controller
{
forumEntities context = new forumEntities();
public ActionResult Index()
{
var q = (from pd in context.ProductStock
join od in context.ProductOrder on pd.ProductId equals od.ProductId
orderby od.OrderId
select new
{
od.OrderId,
pd.ProductId,
pd.ProductName,
od.OrderQty
}).ToList();
return View();
}
}
}