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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:47:12+00:00 2026-05-20T21:47:12+00:00

I have a SQL database with has the following: Customer, Item, Clothing and Food.

  • 0

I have a SQL database with has the following: Customer, Item, Clothing and Food.

Item holds a key to Clothing or Food.
Item also holds a key to Customer. Therefore a customer can have an item, which may be of food or clothing.

I am using ADO.Net Entity Framework and have this generated automatically.

I currently have the following set-up: A person may enter their ID on the webpage and this is sent via a form post where the controller picks it up and queries the database using LINQ to get the customer. The customer view (details) is then returned. I can now see all the customer details etc.

However, what I want is to be able to see the items the customer has, the different food items and clothing items, but I am unsure how to do this. I also want to be able to allow the user to edit one field of the clothes and food items tables. Any idea how I would implement this?

Here is an ActionResult in my CustomerController:

        public ActionResult Details(int id)
    {
        var cust = (from c in dataModel.Customers
                    where (c.MembershipID == id)
                    select c).First();
        return View(cust);
    }

I can also write cust.Items which is the entity which I want to display in the view with the customer (their items). How would I display this in the view also?

Hopefully this makes it a little more clear on what I am trying to achieve and how.

Thanks.

  • 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-20T21:47:13+00:00Added an answer on May 20, 2026 at 9:47 pm

    Using Entity Framework, if you’re tables are linked properly with the right foreign keys and all that then your Customer entity should have a property that is a collection of Items.

    You could also create your own strongly typed ViewModel that has a field for Customer and implement your own properties for Clothing and Food and populate those with another query.

    This question was asked last night but its similar. The guy in the question wanted information to populate a dropdown passed in. You want something similar, not for a dropdown, but to fill in textboxes to edit. How to properly populate drop downs from ViewData in controller on multiple views in ASP.NET MVC

    To create a ViewModel start by creating a new class and name it CustomerAndItemsViewModel, for example.

    public class CustomerAndItemsViewModel
    {
        public Customer Customer { get; set; }
        public IQueryable<Items> Items { get; set; }        
    }
    
    
    public ActionResult Details(int id)
    {
        var cust = (from c in dataModel.Customers
                    where (c.MembershipID == id)
                    select c).First();
        var items = (from i in dataModel.Items
                    where (i.MembershipID == cust.MembershipID)
                    select i;
        return View(new CustomerAndItemsViewModel { Customer = cust, Items = items });
    }
    

    And don’t forget that you will no longer be passing a Customer to your view. So you need to change the line at the top to something like:

    @model Your.Path.To.CustomerAndItemsViewModel
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL database that has the following table: Table: PhoneRecords -------------- ID(identity
I have a following scenario in my SQL Server 2005 database. zipcodes table has
I have a SQL Server database which has grown to more than 15GB in
I have created an application which has the following: A database created in VS2008,
I have a simple database table (SQL Server 2008 R2 Express), which has a
I have a table in SQL Server 2005 database that has following columns: Id,ProductName,Year,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
I have a database with the following table structures... The Customer table has two
I have an unusual SQL table (not mine) which has the following fields (among
I have a SQL database that has a table with a field set to
I have a SQL Server 2005 database that has been deleted, and I need

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.