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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:15:13+00:00 2026-06-15T21:15:13+00:00

Im simply trying to mock up a data model in POCO. But I’m a

  • 0

Im simply trying to mock up a data model in POCO. But I’m a little confused about something. Lets just assume for this example that I will be using Entity Framework for ORM. First I have a Phone and Address class:

public class Phone
{
    int Id { get; set; }
    int Number { get; set; }
}

public class Address
{
    public int Id { get; set; }
    public string Street { get; set; }
    public string Suite { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public int Zip { get; set; }
}

Next I have a Person and a Company class:

public class Person
{
    int Id { get; set; }
    string FirstName { get; set; }
    string MiddleName { get; set; }
    string LastName { get; set; }
    string Prefix { get; set; }
}

public class Company
{
    int Id { get; set; }
    int Name { get; set; }
}

Say I want both Person and company to have Phone or address lists so logically the way I might think about this from a code perspective would to create an abstract class, AContact:

public abstract class AContact
{
    ICollection<Phone> Phone { get; set; }
    ICollection<Address> Address { get; set; }
}

And make my Company and Person then inherit this:

public class Company : AContact
{
    int Id { get; set; }
    int Name { get; set; }
}

public class Person : AContact
{
    int Id { get; set; }
    string FirstName { get; set; }
    string MiddleName { get; set; }
    string LastName { get; set; }
    string Prefix { get; set; }
}

Alternatively I might create an Interface:

public interface IContact
{
    ICollection<Phone> Phone { get; set; }
    ICollection<Address> Address { get; set; }
}

And Implement the interface:

public class Company : IContact
{
    public int Id { get; set; }
    public int Name { get; set; }
    public ICollection<Phone> Phone { get; set;}
    public ICollection<Address> Address {get; set;}
}

Now I understand the difference here between abstract classes and interfaces. But how is this supposed to be implemented for Entity Framework to function? From a little searching around on the web it seems that as of 4.1 you can not do the Interface thing, so does that mean I have to use the abstract class? OR do I just have to explicitly define both properties in every class I want to use them in? Also what about something like RavenDB would this work there as well?

  • 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-15T21:15:14+00:00Added an answer on June 15, 2026 at 9:15 pm

    Both options are possible.

    When using your interface your DbContext will look like:

    public class MyContext : DbContext
    {
        public IDbSet<Company> Companies { get; set; }
        public IDbSet<Person> People { get; set; }
    }
    

    You will get back Companies and People objects that also happen to implement the interface you specify.

    When using the abstract class you will have the following:

    public class MyContext : DbContext
    {
        public IDbSet<AContact> Contacts { get; set; }
    }
    

    With the abstract base class, you will have one entity set. With the OfType<T> you can filter the collection down to specific times.

    RavenDB is a whole other subject. It’s a NoSql database that works really smooth. It serializes your objects to JSON and just stores them for you. You can use (almost) every class structure you want.

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

Sidebar

Related Questions

Maybe im missing something but im not sure. All im simply trying to do
I am trying to figure out how can I mock (simply) current_user inside my
Probably a simple answer that's mock or stub related but I'm newish and trying
I simply trying (in vain) to remove all instances of the word 'at' during
I'm simply trying to convert a CGEventTimestamp (which is an unsigned 64-bit integer roughly
I'm simply trying to crop a JPEG image (no scaling) using PHP. Here is
I am simply trying to draw a rectangle inside of a panel using flex4.
I am simply trying to display a users location on a map, I am
Ok, I'm very simply trying to take this example... http://jsfiddle.net/shanabus/HGF59/ and put it on
Trying to turn this: href=/wp-content/themes/tray/img/celebrity_photos/photo.jpg into: href=/img/celebrity_photos/photo.jpg So I'm simply trying to remove /wp-content/themes/tray/

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.