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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:04:51+00:00 2026-05-12T22:04:51+00:00

I generated a Members table and a MembersType table which has a primary key

  • 0

I generated a Members table and a MembersType table which has a primary key which links to the Type foreign key in the Members table. The MembersType table is literally just 3 records, so that each Member can be of MemberType 1, 2 or 3.

Now the problem is that when Entity Framework generates the data layer and objects for the Members object, it creates a MemberType object in the Members object, but all I want to be able to do when setting it is:

 Members.MemberType = 1;

but because of the above, I have to do this:

 MemberTypes = db.MemberTypes.Where(x => x.MemberTypeId == 1).AsQueryable().First()

Is there anyway to stop it from generating an object on foreign keys so I can just set it as an int? Surely this is more quicker and resource efficient than querying the type table everytime too.

  • 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-12T22:04:51+00:00Added an answer on May 12, 2026 at 10:04 pm

    You have encountered one of everyone’s least favorite features of EFv1. The problem is that everything is an Entity, so you can’t get to foreign key values as primitives.

    Your code sample shows how it has to be done in EFv1. The best you can do is cache those enum values up front so you don’t have to keep getting them from the context. EFv4 does away with this restriction with “FK Properties,” which is just a fancy way of saying raw foreign keys you can set directly.

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

Sidebar

Ask A Question

Stats

  • Questions 230k
  • Answers 230k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's a pretty simple example for you. Window1.xaml: <Window x:Class="CTDExample.Window1"… May 13, 2026 at 2:01 am
  • Editorial Team
    Editorial Team added an answer Chances are you're seeing JIT compilation. On my box, I… May 13, 2026 at 2:01 am
  • Editorial Team
    Editorial Team added an answer Do you understand the concept of recursion? If so, figure… May 13, 2026 at 2:01 am

Related Questions

Trying to use Linq to SQL for a small project I'm working on at
I need to parse Visual Studio automatically generated XML documentation to create a report.
For a school project I'm making a simple Job Listing website in ASP.NET MVC
In .NET 2.0 (in this case VB), is there a standard API that'll serialize
I am using asp.net mvc. I have generated a view that retrieve all unapproved

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.