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

  • Home
  • SEARCH
  • 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 8851973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:17:15+00:00 2026-06-14T13:17:15+00:00

I am stuck trying to get my model populated given the domain table structure.

  • 0

I am stuck trying to get my model populated given the domain table structure.

I have a main table that stores Vendors and each Vendor can select one-to-many categories from a master category lookup table. The vendor selections are stored in another table that only stores the VendorID and CategoryID to link between them.

I can write the query (below) to include the category table but then I can only display the categoryID and not the category names.

        public VendorProfile GetVendor(String id)
    {
        Guid pid = Guid.Parse(id);
        var view = _db.VendorProfiles.Include("VendorCategories").Single(v => v.ProfileID == pid);
        return view;
    }

I attempted to include the lookup table in the query (below) but this is generating a runtime error.

        public VendorProfile GetVendor(String id)
    {
        Guid pid = Guid.Parse(id);
        var view = _db.VendorProfiles.Include("VendorCategories").Include("ProductServiceCategory").Single(v => v.ProfileID == pid);
        return view;
    }

A specified Include path is not valid. The EntityType ‘VendorProfilesIntranet.VendorProfile’ does not declare a navigation property with the name ‘ProductServiceCategory’.

The Category table does have the navigation property. I don’t know how to add this same navigation property to the main table since it does not have any FK to the lookup table.

UPDATE:

@Gert This notation does work!

_db.VendorProfiles.Include("VendorCategories.ProductServiceCategory").Single(v => v.ProfileID == pid);

However, what I get displayed now is only the category items that were selected. I wish to get the entire list of catgories and have the ones checked that were selected. I am using a scrolling CheckboxList.

       <div class="scroll_checkboxes">
        <ul>
        @foreach (var c in Model.VendorCategories)
        {
           <li>
               <input type="checkbox" name="categories" value="@c.ID" /> @c.ProductServiceCategory.CategoryName
           </li>
        }
        </ul>
        @Html.ValidationMessage("Please check at least one Product/Service category")
    </div>

UPDATE2:

There might be a better solution but for anyone stuck with similar situation, this worked

        <div class="scroll_checkboxes">
        <ul>
        @foreach (var c in ViewBag.Categories)
        {
           <li>
               @foreach(var vc in Model.VendorCategories)
               {
                   if(c.Id == vc.CategoryID)
                   {
                        <input type="checkbox" name="categories" checked="checked" value="@c.Id" /> @vc.ProductServiceCategory.CategoryName
                       <br />
                   }
                   else
                   {
                        <input type="checkbox" name="categories" value="@c.Id" /> @vc.ProductServiceCategory.CategoryName
                        <br />
                   }
               }
           </li>
        }
        </ul>
        @Html.ValidationMessage("Please check at least one Product/Service category")
    </div>
  • 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-14T13:17:16+00:00Added an answer on June 14, 2026 at 1:17 pm

    You can do

    _db.VendorProfiles.Include("VendorCategories.ProductServiceCategory")
    

    to include both the VendorCategories and their ProductServiceCategorys in the result set.

    By the way, if you use DbExtensions.Include you have intellisense to help you find the right include paths.

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

Sidebar

Related Questions

I am trying to learn Backbone.js and have stuck at an issue. model.save is
I'm stuck trying to get a WinInet HTTP POST via SSL using ONLY C.
I'm stuck trying to get a regex to match a filetype in a sorting
Sometimes I still get stuck trying to translate procedural code into functional code. Is
I'm kinda stuck on something... I'm trying to get #right to be the same
I'm trying to understand why my code get stuck in the for loop of
I am trying to design my Class Diagram. But I get stuck on this
I'm stuck trying to retrieve data from an associated model store. Allow me to
I'm a little stuck trying to get my head around a django template. I
I'm trying to get a nested model to bind correctly with a nested view

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.