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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:06:37+00:00 2026-06-10T10:06:37+00:00

I have some domain classes that look something like this, that I want to

  • 0

I have some domain classes that look something like this, that I want to model with Code First (in EF 4.3).

public class Foo {
    // ...
}

public class Bar {
    // ...

    public Foo Foo { get; set; }
}

public class Baz {
    // ...

    public Foo Foo { get; set; }
}

In every example I see though, foreign object references are added in the Foo class. Can my Foo class be agnostic of the Bar and Baz class, or do I really need to do something like this?

public class Foo {
    // ...
    public virtual Bar { get; set; }

    public virtual Baz { get; set; }
}

According to this answer, classes do need to have navigation properties. I’m new at Code First, so can anyone explain why this might be the case? Is there a way I can avoid polluting my Foo class like this by using the Fluent API?

It seems weird to me that Foo would need to know about every class that uses it. Is my design simply fundamentally flawed in some way?

  • 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-10T10:06:39+00:00Added an answer on June 10, 2026 at 10:06 am

    The other answer is partly correct.

    If you want code-forst to bootstrap your database model with relationships between the tables you’ll have to define at least in one class a navigation property.

    The mapping will of course also work without the relationship, but you won’t have the constraints on the database/sql level. Unless you add them with migrations or some other sql-scripts.

    Though in your example I am not quite sure what kind of relationship you’re trying to define anyhow. Is that supposed to be a one-to-one relationship?

    In that case, Foo doesn’t need to know about any other class that has a reference to it, as answered in your linked question, only one class needs to have it.

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

Sidebar

Related Questions

I have some code that looks like the following. First I have some domain
I have some code looking like this: using System.Threading; public sealed class MyClass :
Assume some domain and view objects (that have no common base class) public class
Our domain model is very tightly coupled and some classes that are mapped with
I have designed some classes using Visual Studio class diagramming. Now I would like
My domain classes that have one-to-many mappings generally take the following form (untested code):
I've got a rich domain model, where most classes have some behaviour and some
suppose I have a domain classes: public class Country { string name; IList<Region> regions;
I have some methods that are common across a few of my domain classes.
I have some pdf files located on a http server: Like: http://domain.com/files/file1.pdf http://domain.com/files/file1.pdf http://domain.com/files/file1.pdf

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.