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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:56:42+00:00 2026-05-11T10:56:42+00:00

I have a Foo entity in Entity Framework. But I’m making it inherit from

  • 0

I have a Foo entity in Entity Framework. But I’m making it inherit from IFoo so that my business logic only knows IFoo – thus abstracting Entity Framework away.

The problem is that Foo has a collection of Bar entities. And this collection is of type EntityCollection<Bar> .

If I put this collection in IFoo as it is, I make IFoo dependent on Entity Framework. So I thought of putting it as ICollection<IBar>, but this doesn’t compile (naturally).

The only solution I can think of is to go to the concrete Foo implementation generated by the Entity Framework designer and change the collection from EntityCollection<Bar> to ICollection<IBar> there. But I dread the thought of the implications this will have on Entity Framework ‘behind the scenes’.

Is there any way for me to define IFoo and IBar independently of Entity Framework while still maintaining Foo and Bar as EF Entities that implement them? Do IFoo and IBar even make sense, if I cannot achieve this independence that I aim for?

  • 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. 2026-05-11T10:56:43+00:00Added an answer on May 11, 2026 at 10:56 am

    The general concept you are referring to is ‘persistence ignorance’ (PI), although that generally applies directly to entities themselves rather than the code that consumes the entities.

    In any case, Hibernate and NHibernate natively support PI, but the initial version of Microsoft’s Entity Framework does not. MS caught a lot of flak for this and PI is probably the #1 most discussed feature for the next version (whenever that is).

    As far as what you are trying to do with interfaces, does the collection of Bars need to be modified after it is retrieved? If the answer is yes, there is no easy answer. Even covariance couldn’t help you here because ICollection<T> has an Add method.

    If the collection is read-only, then you might consider exposing it as IEnumerable<IBar>. The Enumerable.Cast method makes this fairly convenient.

    interface IFoo {     IEnumerable<IBar> Bars { get; } }  partial class Foo : IFoo {     IEnumerable<IBar> IFoo.Bars     {         get { return Bars.Cast<IBar>(); }     } } 

    Also, I know of at least one effort to make the current version of EF support persistence ignorance.

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

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think the maximium size of a cookie is about… May 11, 2026 at 11:32 pm
  • Editorial Team
    Editorial Team added an answer Changed: <xsl:template match="xs:complexType"> <xsl:copy> <xsl:choose> <xsl:when test="*[self::xs:element]|@*"> <xsl:copy-of select="."/> </xsl:when>… May 11, 2026 at 11:32 pm
  • Editorial Team
    Editorial Team added an answer You have defined your event to use the EventHandler delegate.… May 11, 2026 at 11:32 pm

Related Questions

I have a Foo entity in Entity Framework. But I'm making it inherit from
One type of entity in my model (let's call it E1) needs to be
I have a complete separation of my Entity Framework objects and my POCO objects,
I'm having problems querying the entity model to get additional information. My db has
I'm trying to use the DataAnnotationsModelBinder in order to use data annotations for server-side

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.