Home > DeveloperSection > Forums > Linq Inner Join with AND condition
Norman Reedus
Norman Reedus

Total Post:45

Points:315
Posted on    March-15-2016 11:00 PM

 LINQ C#  LINQ  Mvc 
Ratings:


 1 Reply(s)
 213  View(s)
Rate this:
We want to Inner Join with AND condition. How to write  Inner Join with AND condition in linq query.Please Help me.


aditya kumar Patel

Total Post:244

Points:1736
Posted on    March-15-2016 11:12 PM

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();

}

}

}


Don't want to miss updates? Please click the below button!

Follow MindStick