Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1114365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:59:44+00:00 2026-05-17T02:59:44+00:00

this is the case: ASP.NET MVC C# Model: I would like to use information

  • 0

this is the case: ASP.NET MVC C#

Model: I would like to use information defined on three tables, Product – Details – Pictures. I created a ProductRepository and defined a join of the three tables. Finally I select fields from each of these tables.

    public IQueryable ProductsList()
    {
        var db = new Entities();
        var results = from p in db.Products
                    join pi in db.ProductPic on p.ProductId equals pi.ProductId
                    // first join
                    join pv in db.ProductDetails on p.ProductId equals pv.ProductId
                    // second join
                    select new
                               {
                                   p.Name,
                                   p.Description,
                                   p.PCategory,
                                   p.ProductPicture,
                                   pv.Price,
                                   pi.Picture,
                               };
        return (results);
    }

Controller: I defined:

    public ActionResult Index()
    {
        var products = productrepository.ProductsList();
        if (products == null) throw new NotImplementedException();
        else
        return View("Index", products);
    }

Views: I created a strongly typed view from model Products.

When I create the view I only received the fields from Table Product, but not the fields from table Details and Picture.

My main question resides in the way it has to be created a View in order to use all the fields defined on the model (in this case = productrepository.productslist(); At this moment when I scaffold directly I only receive fields from product using strongly typed with product.

Thank you so much!.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:59:45+00:00Added an answer on May 17, 2026 at 2:59 am

    You strongly-typed your view to a Product type but your EF query returns an anonymous type that includes other fields. Create a class for the product view model:

    class ProductViewModel
    {
        public string Name { get; set; }
        public string Description{ get; set; }
        public string PCategory{ get; set; }
        public string ProductPicture{ get; set; }
        public string Price { get; set; }
        public string Picture { get; set; }
    }
    

    Then in the select of your EF query, populate this type rather than your anonymous type. Also, you should independently verify that your EF query is returning the expected results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ASP.Net MVC with C# language. I would like to edit a
I am using ASP.Net MVC with ADO.Net Entity Data Model. When I use ToList()
I've got controller code like this all over my ASP.NET MVC 3 site: [HttpPost]
With ASP.net MVC I have a Model like so: public class Project { public
I'm developing my first ASP.NET MVC app and what I'd like to accomplish is
I'm using ASP.NET, but I'm sure this pertains to any (or most) MVC frameworks.
I've inherited a system which was written in MVC. This system uses the asp.net
I am implementing a new ASP.NET MVC 3 application that will use a form
I'm just starting to learn ASP.NET MVC and I'd like to know how I
I really like the way ASP.NET MVC works. I'd love to implement it on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.