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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:16:36+00:00 2026-05-19T15:16:36+00:00

I am using EF4 CTP5. Here are my POCOs: public class Address { public

  • 0

I am using EF4 CTP5. Here are my POCOs:

public class Address
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Line1 { get; set; }
    public string Line2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string PostalCode { get; set; }
}

public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public List<Address> Addresses { get; set; }
    public List<Order> Orders { get; set; }
}

public class Order
{
    public int Id { get; set; }
    public decimal Total { get; set; }
    public Address ShippingAddress { get; set; }
    public Address BillingAddress { get; set; }
}

Is there a way to get Address to be a ComplexType for the Order class? After playing around with this, I’m guessing not, but maybe there’s a way I haven’t seen.

EDIT: In response to Shawn below, I gave it my best shot:

//modelBuilder.Entity<Order>().Ignore(o => o.BillingAddress);
//modelBuilder.Entity<Order>().Ignore(o => o.ShippingAddress);
modelBuilder.Entity<Order>()
    .Property(o => o.BillingAddress.City).HasColumnName("BillingCity");

Fails at runtime with error “The configured property ‘BillingAddress’ is not a declared property on the entity ‘Order’.” Trying to use Ignore() doesn’t work. Next, the Hanselman article is CTP4, but the CTP5 equivalent is:

modelBuilder.Entity<Order>().Map(mapconfig =>
{
    mapconfig.Properties(o => new {
        o.Id
        , o.Total
        , o.BillingAddress.City
    });
    mapconfig.ToTable("Orders");
});

Fails with error “Property ‘BillingAddress.City’ of type ‘Order’ cannot be included in its mapping.”

I give up. Maybe the final release will have something like this. Or maybe I need to switch to NHibernate =)

  • 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-19T15:16:37+00:00Added an answer on May 19, 2026 at 3:16 pm

    All you need to do is to place ComplexTypeAttribute on Address class:

    [ComplexType]
    public class Address
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Line1 { get; set; }
        public string Line2 { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string PostalCode { get; set; }
    }
    

    Alternatively, you can achieve this by fluent API:

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.ComplexType<Address>();
    }
    

    But you cannot have Address type as to be both an Entity and a Complex Type, it’s one way or another.

    Take a look at this blog post where I discuss this at length:

    Associations in EF Code First CTP5: Part 1 – Complex Types

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

Sidebar

Related Questions

I am using EF4 CTP 5, CodeFirst. Please see my classes first: public class
I'm using EF4.1 POCO. I have two tables [Table(Parent)] public class Parent { public
I'm using EF4 CTP5 code first approach but am having trouble getting it to
I am using EF4 CTP5 to try to persist a POCO object that is
I am trying to do some tests using EF4 + CTP5 with code first
I am using POCO classes on an EF4 CTP5 project and I am having
I am using EF4 Code First (CTP5) to generate my database and I am
I'm using code-first in Web Forms (not MVC) with EF4 and CTP5, and when
I'm trying to implement encrypted columns in EF4 and using the CTP5 features to
I'm using the EF4.1 DbContext code generation, which creates POCO entities like this: public

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.