I'm trying EF with the EFPocoAdapter for the first time. I have a relatively simple TPH scenario with one table and two types, each inheriting from an abstract base class.
My model validates through EdmGen, and my PocoAdapter.cs and xxxEntities.cs files generate fine as well. (well, actually, there are some namespace probems that i'm currently tweaking by hand until we figure out where to go next.)
When I run a simple test to retrieve data:
using (CINFulfillmentEntities context = new CINFulfillmentEntities())
{
// use context
var alerts = from p in context.Notifications.OfType<Alert>()
select p;
foreach (var alert in alerts)
{
Assert.IsNotNull(alert);
}
}
I get an error in the PocoAdapter class, claiming that PocoEntity is null is the following method inside my base class's adapter:
public override void PopulatePocoEntity(bool enableProxies)
{
base.PopulatePocoEntity(enableProxies);
PocoEntity.Owner = _Owner.CreatePocoStructure();
if (!(PocoEntity is IEntityProxy))
{
}
Any ideas from anyone?
}
So, after a little more debugging, I think this is related to proxies. Inside PocoAdapterBase we have the following method: protected PocoAdapterBase(TPocoClass pocoObject) { _context = ThreadLocalContext.Current; bool allowProxies = false; if (_context != null) { allowProxies = _context.EnableChangeTrackingUsingProxies; } _pocoEntity = pocoObject ?? (TPocoClass)(allowProxies ? CreatePocoEntityProxy() : CreatePocoEntity()); Init(); InitCollections(allowProxies); RegisterAdapterInContext(); }
The line that sets _pocoEntity calls CreatePocoEntityProxy, which returns null.
More info as I find it...