HOW TO SELECT AND RETRIEVE DATA USING LINQ QUERY IN ENTITY FRAMEWORK

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
 819  View(s)
Ratings:
Rate this:
I want to  select and retrieve data using  linq query in entity framework how to do this please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: how to select and retrieve data in linq query in entity framework


    index.cshtml

    @model IList<ForumMVC.CUSTOMER>
    @{
        ViewBag.Title = "WebGrid CRUD Operations";  
    }

    <table style="background-color: #ccc; width: 100%;">
        <thead style="background-color: red;">
            <tr>
                <th>ID</th>
                 <th>Name</th>
                 <th>Phone</th>
                 <th>Email</th>
                 <th>Address</th>
            </tr>
        </thead>
        <tbody style="background-color: #ddd;">
            @foreach(var obj in Model)
            {
            <tr>
                <th>@obj.CUST_ID</th>
                 <th>@obj.CUST_NAME</th>
                 <th>@obj.CUST_PHONE</th>
                 <th>@obj.CUST_EMAILID</th>
                 <th>@obj.CUST_ADDRESS</th>
            </tr>
            }
        </tbody>
    </table>

    Controller

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using ForumMVC;
    using System.Data.Entity;
    using ForumMVC.Models;
    namespace ForumMVC.Controllers
    {
        public class HomeController : Controller
        {
            forumEntities1 db = new forumEntities1();
            public ActionResult Index()
            {
                IList<CUSTOMER> data = db.CUSTOMER.Where(p => p.CUST_ID < 70 && p.CUST_ID > 50).ToList();
                return View(data);
            }

        }
    }

     

      Modified On Jan-22-2016 12:48:14 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!