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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:33:41+00:00 2026-06-01T11:33:41+00:00

I am creating a new database model using Entity Framework 4.3 Code-FIrst; using Fluent

  • 0

I am creating a new database model using Entity Framework 4.3 Code-FIrst; using Fluent API. Dummy model is below.

So my main object is Something and I need to keep track of this. All the other items are supplimentary. Normally in a Database I would assign a Table such as Contact, a primary key and a foregin key for relationship. However, reading more about about the Fluent API and Complex Types, especially this article, I have noticed (i think) that I can let EF take care of linking those objects/tables and I don’t have to worry about them as Repositories in my MVC app.

So please note:

  • Something has a one to many with Contact
  • Contact has one to many with Address
  • Contact has one to many with PhoenNumber

Knowing this, my confusion lies in the Complex Types because Contact is a Complext Type to Somethign and Address & PhoneNumber are Complex Types to Something.

  • How would I set this relationship in Fluent API?
  • How would I say that Address is required?
  • Using domain driven development in ASP.NET MVC, would I have to maintain a repository of IContactRepository and IAddressRepository to push to a controller?

(please note that some code omitted for brevity.)

// attempt
void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.ComplexType<Contact>();

    modelBuilder.ComplexType<Contact>().Property(p => p.Address).IsRequired();  // COMPILER ERROR

    modelBuilder.ComplexType<Address>();
    modelBuilder.ComplexType<PhoneNumber>();    
}


// DUMMY MODEL
class Something()
{
    void Something()
    {
        this.Contact = new HashSet<Contact>( );
    }

    DateTime DOB { get; set; }
    int YearsEmployed { get; set; }
    ICollection<Contact> Contact { get; set; }
}

class Contact()
{
    void Contact()
    {
        this.Address = new HashSet<Address>();
    }

    ICollection<Address> Address { get; set; }
}

class Address()
{
        string Street1 { get; set; }
        string Street2 { get; set; }
        string State { get; set; }
        string City { get; set; }
        string Zip { get; set; }
        OptionName OptionName { get; set; }
}

class PhoneNumber()
{
    string Number
    OptionName OptionName { get; set; }
}

class OptionName()
{
    string OptionName { get; set; }
}
  • 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-01T11:33:42+00:00Added an answer on June 1, 2026 at 11:33 am

    No neither of your classes is complex type. Complex types must follow strict rules. They cannot contain navigation properties and because they are mapped to the owning entity’s table they cannot be represented in any other form than one-to-one relation with owning entity.

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

Sidebar

Related Questions

I'm having trouble creating a new model row in the database using ActiveRecord in
Using EF 4.1 Code first I wanted to stop EF creating database from Models.
I'm trying to implement the repository pattern using entity framework code first rc 1.
I am using .Net Framework 4.0. I have an entity model (.edmx) and I
I have been using Entity Framework 4.3 on an existing database and I have
Using Microsoft's designer for the Entity Framework (v3.5), I have created an Entity Model
I am creating a new database to manage wish lists. Solution A: Two tables,
I'm creating a new database in my Activity like this: @Override public void onCreate(Bundle
I always ignore this option when creating a new database on SQL Server 2005,
I'm new to SQL and could use some help in creating a database schema

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.