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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:34:02+00:00 2026-05-30T00:34:02+00:00

How do I get the fields in User to map to LookUpDetail using EF

  • 0

How do I get the fields in User to map to LookUpDetail using EF Code First? (preferably using annotations, not FluentAPI)

public class User
{
   public int? ProvStateId { get; set; }
   public LookUpDetail ProvState { get; set; }
   public int? CountryId { get; set; }
   public LookUpDetail Country { get; set; }
}
public class LookUpDetail
{
   public int LookUpDetailId { get; set; }
   public string Value { get; set; }
}

I want both ProvStateId and CountryId to map to LookUpDetailId, and be able to populate ProvState and COuntry when pulling a User record.

I’ve tried

[ForeignKey("ProvStateId")]
public LookUpDetail ProvState { get; set; }

And that seems to set the field in the DB, but
LookUpDetail ProvState
is always null when I try to pull a User record.

The LookUpDetail table is populated and I am able to display it’s contents just fine.

What am I missing?

  • 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-30T00:34:04+00:00Added an answer on May 30, 2026 at 12:34 am

    You need to make the Model class properties to be virtual property that will allow EF framework to create proxy and do load related object for you once you do lazy loading.

    (I am not sure you do lazy loading or not, if not you need to do explicit load related object)
    try this….

    public class User
    {
      public virtual int? ProvStateId { get; set; }
      public virtual LookUpDetail ProvState { get; set; }
      public virtual int? CountryId { get; set; }
      public virtual LookUpDetail Country { get; set; }
    }
    
    public class LookUpDetail
    {
      public virtual int LookUpDetailId { get; set; }
      public virtual string Value { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my controller: @Controller public class UserController { @RequestMapping(value=/admin/user/id/{id}/update, method=RequestMethod.GET) public ModelAndView updateUserHandler(@ModelAttribute(userForm) UserForm
Given the following situation, Entity Framework Code-first missnames/renames the connecting or Join table. public
I have something like this in my Map public class Settings : ClassMap<Setting> {
I'm using Castor to write out a map of user ID's to time intervals.
I am using wordpress as a CMS and trying to allow user fields to
Introduction: I'm trying to get additional fields to log with log4j, and its working
Can you get the distinct combination of 2 different fields in a database table?
I'm trying to get my name and trip input fields to line, but they're
I am trying to get jquery validate to work on multiple fields. Reason being
I need to get the biggest value from two fields: SELECT MAX(field1), MAX(field2) Now,

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.