Click here to Skip to main content
13,356,787 members (66,590 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 21 Dec 2014

Joining Table and Display Data using WCF Service in MVC

, 21 Dec 2014
Rate this:
Please Sign up or sign in to vote.
How to join table and display data using WCF Service in MVC
  1. Create a new Webapplication in MVC.

  2. Create a new database and add two tables which are department_table and employee.

    In Employee table, Did field is foreign key of Department_table.

  3. Now add entity model in website.

  4. In which choose employee and department_table.
  5. Add new Class in which write this field that you want to display in website.

  6. Add WCF Service to website and in Iservice.cs file, write this code:
    List<Class1> getdata();
  7. In Service.cs file, write this code:
    DatabaseEntities obj = new DatabaseEntities();
    public List<Class1> getdata()
        var x = from b in obj.Employees
                join a in obj.Department_table
                       on b.Did equals a.Did
                select new Class1 { Name = b.Name,
                    Address = b.Address,
                    Department = a.Department };
        return x.ToList();
  8. Now Run Service. Then add other MVC website in which also add class which is previously added in website.
  9. Add ServiceReference and in home controller, add this code:
    ServiceReference1.ServiceClient obj = new ServiceReference1.ServiceClient();
     public ActionResult Index()
         var x=obj.getdata();
         var y = x.ToList();
           var data = new  List<Class1>();
           foreach(var item in y)
              data.Add(new Class1
                 Name = item.Name,
       return View(data);
  10. Output of this code is as follows:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Shah Ankita
Software Developer
India India
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 21 Dec 2014
Article Copyright 2014 by Shah Ankita
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid