How to Use join in Linq query mvc .

Total Post:341

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

    Re: How to Use join in Linq query mvc .

    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)

      Modified On Apr-10-2018 06:15:55 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.