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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:53:01+00:00 2026-06-15T01:53:01+00:00

I have 2 Models a customer table and a product table. I am pretty

  • 0

I have 2 Models a customer table and a product table. I am pretty new to MVC and I have created a model and I have the auto generated controller and views for details, delete, create… etc…

My models are:

[Table("Product")]
public class Product
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int ProductId { get; set; }
    public decimal Price { get; set; }
    public int CustomerId { get; set; }
}

[Table("Customer")]
public class Customer
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int CustomerId { get; set; }
    public string Name { get; set; }
}

My question is, how do I display a list of the products based on the customer name. Obviously they are joined by CustomerId but how do I combine controllers. So I want to display some data based on data from another table.

  • 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-06-15T01:53:02+00:00Added an answer on June 15, 2026 at 1:53 am

    You need to add a Navigation Property to Customer.

    [Table("Customer")]
    public class Customer
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int CustomerId { get; set; }
        public string Name { get; set; }
    
        public virtual ICollection<Product> Products { get; set; }
    }
    

    Then you can use that to access the products for a customer.

    public ActionResult ProductsByCustomer(string id)
    {
        // Find the customer by name
        var customer = dbContext.Customer.First(c => c.Name == id);
    
        // Get the customers products
        var customersProducts = customer.Products;
    
        // Send products to the View to be rendered
        return View(customersProducts);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to MVC Razor. I have this view: @model SuburbanCustPortal.Models.CustomerModel @{ ViewBag.Title =
I have a Model created with a table called Customers. It contains the following
I have two models: class Customer(models.Model): (...) class CustomerMemo(models.Model): (...) customer = models.ForeignKey(Customer) text
I have models like this: class Vendor(models.Model): title = models.CharField() class Product(models.Model): ... vendor
I have two models Customer and Transaction Customer has_many :transactions Transaction belongs_to :customer Now
I have two models that are associated with each other. Customer has_one :primary_contact And
I have a model called Customer in google app engine with python: class Customer(db.Model):
I have an Entity Framework data model. Part of the model is a Customer
I have models Product and Category . Category can have many products. ( Product
I have a data model as follows: A Customer has Products and Payment Methods.

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.