Wen we need to apply inner join with and condition. To write query for inner join with and condition we need to make two anonymous types (one for left table and one for right table) by using new keyword and compare both the anonymous types as shown below:
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 prd in context.ProductStock
join ord in context.ProductOrder
on new { a = prd.ProductName,prd.ManufacturedBy } equals new { a = ord.ProductName,ord.ManufacturedBy }
select new
{
ord.OrderId,
prd.ProductId,
prd.ProductName,
prd.ManufacturedBy,
ord.OrderDate,
ord.OrderQty
}).ToList();
return View();
}
}
}
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Wen we need to apply inner join with and condition. To write query for inner join with and condition we need to make two anonymous types (one for left table and one for right table) by using new keyword and compare both the anonymous types as shown below: