Click here to Skip to main content
14,107,154 members
Rate this:
 
Please Sign up or sign in to vote.
I want to show records of multiple table in a single view using entity framework database first approach.

this is my controller class:

What I have tried:

<pre>
     public ActionResult Index()
        {
        var query = (from c in db.tblBlogs
                     join d in db.tblBlogComments on c.id equals d.BlogId
                     join e in
                   db.tblBlogLikes on c.id equals e.BlogId
                     join f in db.tblBlogMedias on c.id equals f.BlogId
                     where c.id == d.BlogId || c.id == e.BlogId || c.id == 
                 f.BlogId
                     select c).OrderByDescending(d => 
               d.id).ToList().Take(6);

            return View(query);
        }


This is Index.cshtml file :
@media ICollection<MVCProject.Models.tblBlog>

     @foreach(var item in Model)
        { <h1>@item.BlogPicture</h1>
          <h2>@item.Title</>
          <h2>@item.Description</h2>
        }

here BlogPicture is in table tblBlogMedia
Title & description is in tblBlogs
Posted

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190518.1 | Last Updated 25 Mar 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100