I'm getting the following error while trying to add an entity to the manager:
Null or pending entities cannot be modified
This is the layout of the data:
User UserId
UserProduct UserProductId
UserId
ProductId
Product ProductId
This is the code I am using that fails:
public void AddProduct(Product product)
{
var userProduct = new UserProduct
{
UserId = UserId,
ProductId = product.ProductId
};
EntityAspect.EntityManager.AddEntity(userProduct);
}
I have tried it with or without setting ProductId = product.ProductId
User.EntityAspect.IsNullOrPendingEntity = false
User.UserProducts IsPendingEntityList = false
What is very interesting is, sometimes if I set breakpoint on the AddEntity line, wait a few seconds, then let it execute, it works.
The detached entity is trying to resolve something and it is failing initially.
This is the stacktrace:
at IdeaBlade.EntityModel.EntityAspect.SetValueWithChangeNotification(DataEntityProperty property, Object newValue)
at IdeaBlade.EntityModel.EntityManager.GenerateId(Object entity, DataEntityProperty entityProperty)
at IdeaBlade.EntityModel.EntityManager.UpdatePkIfNeeded(EntityAspect aspect)
at IdeaBlade.EntityModel.EntityManager.AttachEntityAspect(EntityAspect aspect, EntityState entityState)
at IdeaBlade.EntityModel.EntityManager.<>c__DisplayClass60.<AddOrAttachRelatedEntities>b__5d(EntityAspect w)
at IdeaBlade.Core.EnumerableFns.ForEach[T](IEnumerable`1 items, Action`1 action)
at IdeaBlade.EntityModel.EntityManager.AddOrAttachRelatedEntities(EntityAspect wrapper, EntityState entityState)
at IdeaBlade.EntityModel.EntityManager.AttachEntityAspect(EntityAspect aspect, EntityState entityState)
at IdeaBlade.EntityModel.EntityManager.AttachEntity(Object entity, EntityState entityState)
at IdeaBlade.EntityModel.EntityManager.AddEntity(Object entity)
at Spindlemedia.Models.Security.User.AddProduct(Product product)
At the time of the exception:
UserProduct is successfully added to the manager, with a generated id of -100 and it is in the Added State
UserProduct.Product.EntityAspect.IsNullOrPendingEntity = true
UserProduct.User.EntityAspect.IsNullOrPendingEntity = false
They are both in the same entity manager, so I'm not sure what the issue is.
Thoughts?
Edited by smi-mark - 14-Nov-2011 at 2:27pm