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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:31:36+00:00 2026-06-01T13:31:36+00:00

A little new to EF, so please bear with me if the answer to

  • 0

A little new to EF, so please bear with me if the answer to this is obvious. I’m doing a tutorial that uses EF, and two DbSets are defined like this:

    public DbSet<BrokerageAccount> BrokerageAccounts { get; set; }
    public DbSet<Customer> Customers { get; set; }

The customer class looks like this– it’s a POCO (some code cut for brevity):

public class Customer
{
    public Customer()
    {
        BrokerageAccounts = new HashSet<BrokerageAccount>();
    }

    // Primitive properties
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

    // Navigation properties
    public ICollection<BrokerageAccount> BrokerageAccounts { get; set; }
}

}

The BrokerageAccount class is a POCO as well, very similar in design to Customer.

So far so good. The code I have a question about is below. There is an association made in the main program between Customer and BrokerageAccount that I don’t follow. The code reads like this:

    public Customer GetCustomer(string custId)
    {
        using (var context = DataContext)
        {
            return context.Customers
                .Include("BrokerageAccounts").SingleOrDefault(c => c.CustomerCode == custId);
        }
    }

I can’t figure out how the association/join is made between Customer and BrokerageAccount. I don’t see any config or other files in my VS 2010 project that tells what associates the two DbSets, what foreign key column to use, etc.

Perhaps I’m missing something obvious or a mapping file of some sort, but just because Customer has an ICollection of BrokerageAccount along with a comment above that says “Navigation Properties”, doesn’t make it so. In EF, how are those associations established?

  • 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-01T13:31:38+00:00Added an answer on June 1, 2026 at 1:31 pm

    The normal way of setting up the navigation properties is to use the ModelBuilder, This gives you a fluent api to set up the associations, take a look at this for some in depth stuff about how you go about this.

    http://xhalent.wordpress.com/2011/01/21/configuring-entity-framework-4-codefirst/

    Entity framework will guess at what you meant if you dont set up the nav properties manually, in the above case it will probably set up your nav properties as expected as you only have a single 1-* relationship between customer and BrokerageAccount which appears to be named sensibly.

    There is also an attribute method that you can use to set up the navigation properties.

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

Sidebar

Related Questions

hello i am little new to all this but i want to know that:
A little new to Javascript coding, so please bear with me. I read through
Please I am a little new to this field so pardon me if the
I am a little new to programming so please bear with me. I create
Alright so I'm pretty new to this rails stuff so please bear with me...
Please excuse me if I'm doing something really stupid, but I'm a little new
I'm new to objective-c and Im trying to write a little sample app that
I tried the suggestion from this question with very little success. Please... any help
I am a little confused about two new technologies receiving a lot of buzz
I wonder whether someone may be able to help please. I'm a little new

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.