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; } } }
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.
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.