Hi Silvio,
Thanks for the reply. I'll create a sample using Northwind as requested however in the meantime the following information relating to my model might be useful.
I have an entity call Asset that has a 1 to many association with an entity call SystemItem. The SystemItem entity has a recursive (0..1 to many) associated (Parent/ Children).
If I create a SystemItem as follows I can reproduce the behaviour in my Siverlight application but not in my WPF application (identical model):
var mgr = new MyEntities();
var systemItem= new SystemItem();
systemItem.Id = Guid.NewGuid()
var assetEntityState = systemItem.Asset.EntityAspect.EntityState; // assetEntityState is Detached
var isNullAsset = systemItem.Asset.EntityAspect.IsNullEntity; // isNullCustomer is false
var parentEntityState = systemItem.Parent.EntityAspect.EntityState; // assetEntityState is Detached
var isNullParent = systemItem.Parent.EntityAspect.IsNullEntity; // isNullCustomer is false
mgr.AddEntity(systemItem);
var assetEntityState = systemItem.Asset.EntityAspect.EntityState; // assetEntityState is Attached
var isNullAsset = systemItem.Asset.EntityAspect.IsNullEntity; // isNullCustomer is True
var parentEntityState = systemItem.Parent.EntityAspect.EntityState; // assetEntityState is Detached
var isNullParent = systemItem.Parent.EntityAspect.IsNullEntity; // isNullCustomer is false
I have resolved this issue by quering mgr.Assets (local cache only) before creating a SystemItem. In fact, I don't have to query Assets as any query against the EntityManager will resolve the issue. It seems this issue might be related to the initialisation of the EntityManager. This issue effects all entities in model, not just Assets and SystemItems, where the multiplicity is 1.
If you can't reproduce using NorthwindIB then the problem must be with my model. I can't think where the problem might be. Any ideas?
I thought it might be related by my SystemItem buddy class / metadata - a have a NullValueVerifier attribute on the Asset property. I removed this but still had the issue.
Regards
Ian