Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900