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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:45:47+00:00 2026-06-18T11:45:47+00:00

I have the following Customer class: public class Customer : EntityBase<Customer> { public virtual

  • 0

I have the following Customer class:

public class Customer : EntityBase<Customer>
{
    public virtual int ID { get; set; }
    public virtual CustomerType CustomerType { get; set; }

    public virtual string CompanyName { get; set; }
    public virtual string FirstName { get; set; }
    public virtual string LastName { get; set; }

    public virtual ICollection<Address> BillingAddresses { get; set; }
    public virtual ICollection<Address> ShippingAddresses { get; set; }
}

The Address class looks like this:

public class Address : EntityBase<Address>
{
    public virtual int ID { get; set; }
    public virtual AddressType AddressType { get; set; }
    public virtual bool IsDefault { get; set; }
    public virtual string Name { get; set; }
    public virtual string Line1 { get; set; }
    public virtual string Line2 { get; set; }
    public virtual string Line3 { get; set; }
    public virtual string City { get; set; }
    public virtual string State { get; set; }
    public virtual string ZipCode { get; set; }
    public virtual string Country { get; set; }

    public virtual int CustomerID { get; set; }
    public virtual Customer Customer { get; set; }
}

I want to be able to have multiple of each kind of address on the customer class, but I am having a hard time figuring that out.

I would like to end up with something like this to get to the default address for each type.

public Address DefaultBillingAddress
{
    get
    {
        return BillingAddresses.First(x => x.IsDefault == true);
    }
}

The problem I am having is how do I tell the difference between the AddressType enum on each ICollection?

  • 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-18T11:45:48+00:00Added an answer on June 18, 2026 at 11:45 am

    You are capturing the concept of “address type” in two different ways.

    You have your AddressType enum on Address, and you also have separate

    public virtual ICollection<Address> BillingAddresses { get; set; }
    public virtual ICollection<Address> ShippingAddresses { get; set; }
    

    It’s certainly possible with this model to end up with something in BillingAddresses with AddressType.Shipping and vice versa.

    I would suggest simplifying your object model to

    public virtual ICollection<Address> Addresses { get; set; }
    

    and providing helper methods on Customer that return Billing and Shipping addresses, respectively, from Addresses.

    Having said that, I’m not sure what you mean by

    The problem I am having is how do I tell the difference between the AddressType enum on each ICollection?

    Each ICollection should reference the same AddressType enum.

    Using my suggested approach, you could write

    public Address DefaultBillingAddress
    {
        get
        {
            return Addresses
             .First(x => x.IsDefault == true && x.AddressType == AddressType.Billing);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes public class Person { public virtual int Id {
I have the following classes public class Person { public virtual int Id {
I have the following class: public class OrgAlertList { public string CustMailName { get;
I have the following Entity Framework POCO classes: public class Customer { public int
If I have the following domain object: public class Customer { public virtual Guid
I have the following class: public class DocumentCompare { public string Customer; public string
I have an entity Customer public class Customer { public virtual int ID {
Suppose I have the following types of data: class Customer { String id; //
I have the following class:- public class ContactsDetails { public IEnumerable<AaaUserContactInfo> Info { get;
I have the following (greatly simplified) classes: public class Customer { [Required(ErrorMessageResourceName=Required, ErrorMessageResourceType=typeof(ResourcesCommon.ValidationStrings))] 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.