A referential integrity constraint violation occurred

前端 未结 6 1182
有刺的猬
有刺的猬 2021-01-18 04:54

I\'m trying to update an existing entity.

I have the following code:

public MamConfiguration_V1 Save(MamConfiguration_V1 item)
{
    mMaMDBEntities.M         


        
6条回答
  •  终归单人心
    2021-01-18 05:40

    I encountered this exception under a different set of circumstances, and am posting here since this question comes up when the error message is searched.

    The exception was thrown when calling IObjectContextAdapter.ObjectContext.AttachTo(entitySetName, entity) with a partially-loaded entity. The foreign keys on the entity were defined, but the navigational properties were not loaded. (That is, O.ItemID had a value, but O.Item was null). The specific circumstances did not allow O.Item to be loaded.

    The problem turned out to be that the Object State Manager had loaded the object in a separate method and was already tracking the object defined with the same keys. Since the separate method did not need to track the object state, the issue was resolved by calling IQueryable.AsNoTracking() within that method.

提交回复
热议问题