IPoco?

Published 03 July 07 04:52 AM | andersnoras 

You've probably noticed by now that a new CTP of the Entity Framework has been released. One of the new features is oddly named IPOCO. This is supposedly a step towards persistence ignorance for users of the framework. While people are already having a laugh, trying to come up with the best explanation for what the acronym means, I decided to dig in and find out what this is.

There is little to be found in the bits or the sample code that show how you would write an IPOCO, but I found some information at the MSDN forums.

"Starting in the next CTP you will have the option to use IPOCO where instead of using the generated code you could write your own classes and as long as they have an appropriate attribute indicating that a property is part of the entity, then the framework can persist that property whether or not it's public."
Daniel Simmons - The System.Data.Objects Dev Guy

"You can derive from EntityObject (called Entity in CTPs before June) and implement the property getters/setters yourself. Unless you need IPOCO and the flexibility, deriving from EntityObject provides some of the implementation you would manually have todo with IPOCO.
Brain Dawson - ADO.NET Program Manager

Judging from this and a bit of peeking around in the System.Data.Entity namespace an IPOCO is a class which implements the IEntity interface and has a truckload of Edm* attributes sprinkled around. I'm might be wrong about this but an IPOCO probably looks something like this:

[Serializable]
[EDMEnityType]
[EdmRelationshipRole("FK_Order_Customer", "Customer", 
RelationshipMultiplicity.ZeroOrOne, typeof(Order))] public class Customer : IEntityWithRelationships { private static IEntityChangeTracker changeTracker=
new ChangeTracker(typeof(Customer)); private EntityKey id; public EntityKey Id { get { return id; } set { changeTracker.EntityMemberChanging("Id"); id=value; changeTracler.EntityMemberChanged("Id"); } } [EdmScalarProperty(IsNullable=false)] public string Name { get { return name; } set { changeTracker.EntityMemberChanging("Name"); name = value; changeTracker.EntityMemberChanged("Name"); } } // Lots of similar properties... }

As far as I can tell you have some choices when it comes to the IEntityChangeTracker, either you use one of the built-in change trackers that require a truckload of constructor arguments like entity sets, object state managers, metadata and what not - or you roll your own  (as I've done in this imaginary example).

Again, I might my sample might not be quite right, but I reckon I'm not totally off the wall. As Daniel pointed out in his blog post on the release of the new CTP "this is the first step in that direction (My addition: ...towards POCO) and makes the key change to allow the creation of Entity classes that do not inherit from our base class". IMHO, the ADO.NET team have a long way to go before they achieve persistence ignorance. Implementing an interface is really not an advantage over a base class (unless you need explicit interfaces to avoid name clashes), since you'll have to write all the code yourself. Change tracking and other needed features of an ORM are quite hard to get right, so if I'm right about this, we just got more rope to hang ourselves by from the entity framework. True persistence ignorance cannot be achieved until mscorlib is the only dependency required for an entity.

Filed under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Daniel Simmons said on July 3, 2007 2:05 PM:

Much has been written about this already.  Here's my basic message: Yes, the feedback has been received that we need to get to persistence ignorance (see some of my blog postings for more discussion).  Unfortunately this is a major change that will take us a while to get there.  We're doing it in a series of steps that will take us more and more in that direction.  

The long term vision is that we will support a spectrum of options from complete POCO/persistence ignorance on one end of the spectrum to generated code that inherits from our base classes, etc. on the other end.  The reason we need the spectrum is not only that we want to support users from both camps but also that true persistance ignorance has serious performance implications and we want to provide some tools which would allow you to start with full PI and then add back some persistance awareness as needed to meet your perf goals.

In any case, IPOCO (which stands for "Interface Plain Old CLR Objects" -- yes, I'm aware of the conflict between "Interface" and "Plain Old") is one step along the way.  Supporting IPOCO means that we evolve the framework in the direction we need to go to allow PI eventually.  In the next CTP we'll make some more steps in that direction.  By the time we reach v1 RTM we won't be all the way there (we just didn't realize the importance of this in time), but we will have laid the foundation that will allow us to get there eventually.

- Danny

# John Papa said on July 3, 2007 9:19 PM:

You are right Anders in that IPOCO is jus a step on the path. My belief is that the single biggest reason why the EF won't be in the first release of Orcas is that they are heading in the direction of full POCO and persistence ignorance. I am fully willing to wait a few extra months to get there.

BUt yep, I am laughing at IPOCO ... but not because I think the interface is funny ... but because it is a fun acronym to play with. :)

# Insane World said on July 3, 2007 11:44 PM:

Clarification on IPOCO

Leave a Comment

(required) 
(optional)
(required) 
Enter the code you see below