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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:30:59+00:00 2026-05-29T05:30:59+00:00

Build ViewModel using two models Model 1: Person (Id,Name,Address,Phone,CategoryId) Model 2: Category(CategoryId,CategoryText) ViewModel: PersonViewModel

  • 0

Build ViewModel using two models

Model 1: Person (Id,Name,Address,Phone,CategoryId)

Model 2: Category(CategoryId,CategoryText)

ViewModel: PersonViewModel (Name,Phone, CategoryText)

Question: how would I generate my ViewModel in my controller and forward it to the view:

 var model = (from x in db.Person 
             select new PersonViewModel { 
                    Name = x.Name, 
                    Phone = x.Phone, 
                    CategoryText = ??? }).ToList(); 

How do I generate CategoryText?

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-29T05:30:59+00:00Added an answer on May 29, 2026 at 5:30 am

    You need to join on categories.
    you may be able to include as the following, if not you just need a join. Try the following (I forget if you can include() in this syntax – somethingin my mind tells me you can’t and if that’s the case I’ll delete this shortly as I see someone just posted the join syntax)

    
    var model = (from x in db.Person.Include(o=>o.Category) //assumes EF 4.1 if not try .Include("Category")
                 select new PersonViewModel { 
                        Name = x.Name, 
                        Phone = x.Phone, 
                        CategoryText = x.Category.CategoryText }).ToList(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using MVVM Light to build a WP7 (Windows Phone 7) application. I wish
Following on from this question , I'm using a simple ViewModel class to test
I know I can map two object types with LINQ using a projection as
I'm using AutoMapper to map between a Linq Domain object and a ViewModel to
I had a unit test project for my windows phone 7 app ViewModels using
I'm using mvvm light to build a Silverlight application. Is there a code snippet
Having read all the StackOverflow entries regarding Model-View-ViewModel architecture along with most of the
I am trying to build a sample for myself using MVC3, Razor view engine
Just starting out using MVC3 and hit a problem trying to build a drop-down
I'm attempting to build a WP7 solution file form the command line using MSBuild

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.