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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:53:14+00:00 2026-05-20T14:53:14+00:00

I have a mental debate with myself every time I start working on a

  • 0

I have a mental debate with myself every time I start working on a new project and I am designing my POCOs. I have seen many tutorials/code samples that seem to favor foreign key associations:

Foreign key association

public class Order
{
    public int ID { get; set; }
    public int CustomerID { get; set; } // <-- Customer ID
    ...
}

As opposed to independent associations:

Independent association

public class Order
{
    public int ID { get; set; }
    public Customer Customer { get; set; } // <-- Customer object
    ...
}

I have worked with NHibernate in the past, and used independent associations, which not only feel more OO, but also (with lazy loading) have the advantage of giving me access to the whole Customer object, instead of just its ID. This allows me to, for example, retrieve an Order instance and then do Order.Customer.FirstName without having to do a join explicitly, which is extremely convenient.

So to recap, my questions are:

  1. Are there any significant disadvantages in
    using independent associations? and…
  2. If there aren’t any, what
    would be the reason of using foreign key associations at all?
  • 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-20T14:53:14+00:00Added an answer on May 20, 2026 at 2:53 pm

    If you want to take full advantage of ORM you will definitely use Entity reference:

    public class Order
    {
        public int ID { get; set; }
        public Customer Customer { get; set; } // <-- Customer object
        ...
    }
    

    Once you generate an entity model from a database with FKs it will always generate entity references. If you don’t want to use them you must manually modify the EDMX file and add properties representing FKs. At least this was the case in Entity Framework v1 where only Independent associations were allowed.

    Entity framework v4 offers a new type of association called Foreign key association. The most obvious difference between the independent and the foreign key association is in Order class:

    public class Order
    {
        public int ID { get; set; }
        public int CustomerId { get; set; }  // <-- Customer ID
        public Customer Customer { get; set; } // <-- Customer object
        ...
    }
    

    As you can see you have both FK property and entity reference. There are more differences between two types of associations:

    Independent association

    • It is represented as separate object in ObjectStateManager. It has its own EntityState!
    • When building association you always need entitites from both ends of association
    • This association is mapped in the same way as entity.

    Foreign key association

    • It is not represented as separate object in ObjectStateManager. Due to that you must follow some special rules.
    • When building association you don’t need both ends of association. It is enough to have child entity and PK of parent entity but PK value must be unique. So when using foreign keys association you must also assign temporary unique IDs to newly generated entities used in relations.
    • This association is not mapped but instead it defines referential constraints.

    If you want to use foreign key association you must tick Include foreign key columns in the model in Entity Data Model Wizard.

    Edit:

    I found that the difference between these two types of associations is not very well known so I wrote a short article covering this with more details and my own opinion about this.

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

Sidebar

Related Questions

Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
I'm sure this is fairly simple, however I have a major mental block on
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Having a mental block with going around this query. I have the following tables:
I have just started using the AsyncController in my project to take care of
Just a question on how copy is working...I need some verification for mental sanity
I must have a mental block, but I simply can't find the reverse of
I have hit a mental wall. Basically, this code is supposed to execute and
I've been writing PHP for years, and have used every framework under the sun,
OK so I have a mental block when it comes to regex - but

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.