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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:06:35+00:00 2026-05-27T13:06:35+00:00

As a novice am trying my hands on MVC3,razor, EF I have Three connected

  • 0

As a novice am trying my hands on MVC3,razor, EF I have Three connected Tables that I want to produce a view from it. In a simpleton’s brief the following are about the tables

PJUsers – ID, memUID(this unique Id from membership),FirstName,LastName

PJAwards – user nominates another user for an award, this links with awardtypesID as foreign key ( awardId,bool:awardok)

PJAwartypes – (awardtypeID, awardName)

The query in the controller is like this

    var lists =
from tl in db.PJawards
join u in db.PJUsers on tl.nomineeId equals u.ID into tl_u
join i in db.PJUsers on tl.nominatorId equals i.MemUID into tl_i
where tl.awardOk 
orderby tl.awardDated ascending

from u in tl_u.DefaultIfEmpty()
from i in tl_i.DefaultIfEmpty()
select new
{
   Status = tl.awardOk,
    nomineeFname = u.FirstName,
    nomineeLname = u.LastName,
    award =  tl.PJawards.awardName,
    Dated = tl.awardDated,
    nominatorFname = i.FirstName,
    nominatorLname = i.LastName,
    nomineeCountry = u.Citizen,
    nomineeResidence = u.Residence,
    awardtypeId = tl.ID
};

somewhere i read that i have to construct a model class similar to the query in the controller

{
public class AwardUserInfo
{
    public AwardUserInfo() { }
    public bool Status { get; set; }
    public string nomineeFname { get; set; }
    public string nomineeLname { get; set; }
    public string award { get; set; }
    public string Dated { get; set; }
    public string nominatorFname { get; set; }
    public string nominatorLname { get; set; }
    public string nomineeCountry { get; set; }
    public string nomineeResidence { get; set; }
    public int awardtypeId { get; set; }

}
}

Please I learn by examples so to be able to help me assume I don’t know anything

  • 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-27T13:06:35+00:00Added an answer on May 27, 2026 at 1:06 pm

    somewhere i read that i have to construct a model class similar to the query in the controller

    Try this.

    I guess your ef-model is similar to
    enter image description here

    So You can create a ViewModel class

    public class PJAwardsViewModel
    {
        public int Id { get; set; }
        public string NominatorFName { get; set; }
        public string NomineeFname { get; set; }
        public string AwardName { get; set; }
        public bool IsAwarded { get; set; }
    } 
    

    It will be also good if You add some service class

    public class PJAwardsService
    {
        public static List<PJAwards> GetAll()
        {
            using (var context = new YourDBEntities())
            {
                return context.PJAwards
                    .Include(x => x.PJUsers)
                    .Include(x => x.PJUsers1)
                    .Include(x => x.PJAwartypes).ToList();
            }
        }
    }
    

    (Don’t forget to write using System.Data.Entity; )

    Then You can add a ViewModelHelper class

    public class PJAwardsViewModelHelper
    {
        public static PJAwardsViewModel PopulatePJAwardsViewModel(PJAwards pjaward)
        {
            return new PJAwardsViewModel
            {
                Id = pjaward.Id,
                NominatorFName = pjaward.PJUsers.FirstName,
                NomineeFname = pjaward.PJUsers1.FirstName,
                AwardName = pjaward.PJAwartypes.AwardName,
                IsAwarded = pjaward.IsAwarded
            };
        }
    
        public static List<PJAwardsViewModel> PopulatePJAwardsViewModelList(List<PJAwards> pjawardsList)
        {
            return pjawardsList.Select(x => PopulatePJAwardsViewModel(x)).ToList();
        }
    }
    

    At the end Your controller index method will look like this

    public ActionResult Index()
    {
        var pjawards = PJAwardsViewModelHelper.PopulatePJAwardsViewModelList(PJAwardsService.GetAll().ToList());
        return View(pjawards);
    }  
    

    The only thing You should do is add a view (build the project before). Choose PJAwardsViewModel as a Model class and List as a scaffold template.
    Enjoy it.

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

Sidebar

Related Questions

I'm a novice Python user trying to do something that I think should be
total novice here. Trying to work with sqlalchemy but have hit a problem. class
I am a novice trying to deserialize my result from an onSuccess function as
I am a novice with Solr and i was trying the example that comes
SQL novice here. I'm trying to generate a costing query that outputs employee time
I'm a pretty novice programmer who is trying to make a heartbeat script that
I'm an ANTLR novice that's trying to update an early ANTLR 3.1 grammar to
I'm a JavaScript novice trying to build a basic share button as a learning
I'm an encryption novice trying to pass some values back and forth between systems.
SQL novice here. I'm trying to get a list of invoice numbers. There are

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.