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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:05:13+00:00 2026-06-09T12:05:13+00:00

The official approach to defining navigation properties for complex entities is: public class SuperEntity

  • 0

The official approach to defining navigation properties for complex entities is:

public class SuperEntity
{    
    public int Id { get; set; }
    //Other properties
}

public class LowerEntity
{
    public int Id { get; set; }
    public int SuperEntityId { get; set; }
    public virtual SuperEntity SuperEntity { get; set; }    
    //Other properties
}

The main thing here is that a class that references (allows navigation to linked super entity) has both public SuperEntity SuperEntity { get; set; } property, as well as it’s Id in public int SuperEntityId { get; set; }.

I have gone a few days into my entities design ommiting the public int SuperEntityId { get; set; } property in the “lower entities”. So I am navigating only by virtual SuperEntity property. And everything works fine! But I had people on SO telling me that it creates an excessive tables in the DB. I’ve checked, and that is not true. When I use my approach, the DB tables has the SuperEntityId column and just populates it with the referenced entity Id automatically. What’s the point in this public int SuperEntityId { get; set; } field then?

Or, perhaps, what I am doing became available in a “fresh” versions of EF like 4.3?

  • 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-06-09T12:05:14+00:00Added an answer on June 9, 2026 at 12:05 pm

    The point of SuperEntityId is that it is sometimes easier to use a foreign key property in apps where your context isn’t alive the entire time, e.g. a webapp.
    In such a situation, it’s a lot easier to just use a foreign key property, than to try to attach object B to object A.
    As far as I know, with nav properties, EF uses an object to track the relation between 2 objects. So if you want to couple object B to object A, in a disconnected app, it’s not enough to just set the property on object A, you also have to fiddle with the entry of object A in the changetracker to register the relation between B and A.
    Setting a foreign key property is the equivalent of this fiddling.
    When we were just beginning with EF and didn’t know about all of this, every time we wanted to connect 2 objects, e.g. B to A, and B already existed in the DB, the context thought that B was a new object instead of an existing one, and duplicated the record in the DB.

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

Sidebar

Related Questions

Official appengine documentation says that if we set threadsafe property to true in app.yaml
Does an official URN for the MIME type exist? Mozilla Firefox and other applications
Official guide says: Tomcat deployment is trivial and requires copying the WAR file into
I read in Sun official documentation (or Sun online tutorial) about dotted naming for
I've read the official guide about different densities and resolutions, but cannot find how
I followed official tutorials to install FOSUser then SonataUser bundles and my app/Application/Sonata/UserBundle/Entity extension.
What is their official position towards clojure?
Aside from the official GWT blog, which GWT blogs do you read?
This snippet from official website works as expected: $treeObject = Doctrine::getTable('Category')->getTree(); $rootColumnName = $treeObject->getAttribute('rootColumnName');
Is there an official Visual Studio test project template for NUnit? If not, what

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.