Home > DeveloperSection > Forums > How to Use join in Linq query mvc .
Ankit Singh

Total Post:341

Posted on    November-30-2015 10:32 PM

 .NET LINQ  Bootstrap  Mvc 

 1 Reply(s)
 813  View(s)
Rate this:
I want to use Use join in Linq query please help me.

aditya kumar Patel

Total Post:254

Posted on    November-30-2015 10:34 PM

LINQ has a JOIN query operator that provides SQL JOIN like behavior and syntax. As you know, Inner join returns only those records or rows that match or exists in both the tables. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Threading.Tasks;
using System.Diagnostics;
using ForumMVC;
using System.Threading;
using ForumMVC;
namespace ForumMVC.Controllers
    public class HomeController : Controller
        forumEntities  db = new forumEntities();
        public ActionResult Index()
            var result = from t in db.Customer
                         join x in db.Order on t.CustomerID equals x.CustomerID
                         select (new CustomerData {CustomerID=t.CustomerID,CustomerName=t.CustomerName,Amount=x.amount });
            return View(result.ToList());
   public  class CustomerData
       public int CustomerID { get; set; }
       public string CustomerName { get; set; }
       public decimal? Amount { get; set; }
 @model IList<ForumMVC.Controllers.CustomerData>
 @using ForumMVC.Controllers;
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<table class="table table-hover table-bordered table-condensed table-striped">
        <th>Customer Name</th>
       @foreach(CustomerData obj in Model)

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

Follow MindStick