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 6540917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:02:23+00:00 2026-05-25T11:02:23+00:00

I have a table name Product and another table name category. Product table has

  • 0

I have a table name “Product” and another table name “category”.
Product table has ‘productID’, ‘productName’ and ‘CategoryID’.
Category table has ‘categoryID’ and ‘categoryName’.

My target is to display a list of products with category. The list will contain ‘product id’, ‘product name’ and ‘category name’.

I have created a viewmodel. the code is

public int prodID{get;set;}
public int prodName{get;set;}
public int catName{get;set;}

In my controller, I have:

var query= from p in dc.Product
                      select new {p.ProductID,p.ProductName,p.Category1.CategoryName };
var prod = new ProductIndexViewModel()
        {
            ProductList=query //this line is problematic !!it says an explicit conversion exists....
        };
        return View(prod);

How would I write my controller code so that it matches with the viewmodel??

  • 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-25T11:02:23+00:00Added an answer on May 25, 2026 at 11:02 am

    Maybe you will use your view model class directly:

           var query = from p in dc.Product
                        select new ProductIndexViewModel() { 
                            prodID = p.ProductID, 
                            prodName = p.ProductName, 
                            catName = p.Category1.CategoryName 
                        };
    
            List<ProductIndexViewModel> productForView = query.ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table like this: Table name: PRODUCT ID PRODUCTID PRODUCTNAME 1 D100
I have table called product product_id product_Name product_Price product_Description product_image category_id another table category
I have a table product with colums product_id prodcut_name category_id another table category category_id
i have two tables product product_id product_Name product_Price product_Description product_image category_id another table category
I have 2 tables product and history product table: id name type price location
I have a table which contains a list of categories and and another table
Hi I have table called Sold Products which stores buying information for product &
Let's say I have a list of products. I want to display a list
Let's say I have a Product , Category , and Product_To_Category table. A Product
I have a PRODUCTS table, and each product can have multiple attributes so I

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.