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 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

Related Questions

I've got a database which has a table called m_AttentionFlags which references a primary
I have a table that stores membership records. One record per member, per year.
Assume an ASP.NET MVc application has a protected members area. Some URLs generated contain
I have a dataset of around 150 million records that's generated daily it contains:
A table row is generated using an asp:Repeater: <asp:repeater ID=announcementsRepeater OnItemDataBound=announcementsRepeater_ItemDataBound runat=Server> <itemtemplate> <tr
I'm starting to spec out an image gallery type system similar to Facebook's. Members
I'm using IgnitedDatatables (CodeIgniter library) for DataTables . The table gets generated without problems
Summary: I am pulling a list of user IDs from a members transaction table
I am using asp.net mvc. I have generated a view that retrieve all unapproved
I have a members only website in which the logged in users fill in

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.