I am having trouble when deleting a relationship from entity framework when I have declared the relationship as a split table.
Basically I need to have some code that will check if the entity was loaded by the same context. The check below does not work.
var data = new ProductItemData() { Id = pv.ProductItems[i].Id };
if (m_Context.ProductData.Where(w => w.Id == data.Id).Count() == 0)
{
m_Context.ProductData.Attach(data);
}
m_Context.ProductData.Remove(data);
When its not loaded in the same context, i.e data has been lazy loaded from database, I rightly get this error
The object cannot be deleted because it was not found in the ObjectStateManager.
And when the item is in the same context and the attach() method is executed. I get this error
An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key
Does anyone have an idea on a check I can do?
I think it ignores any checks I do..It removes it fine when I reload the context but on the same context, it always goes to the attach code
Thanks