Entity Framework Conflicting changes to the role of the relationship have been detected

1

I have 2 objects that use a third party in common and I have a problem in the routine:

1) Creating a new Manufacturer

var fab = new Fabricante();
DBSet.Add(fab)   
//Sem SaveChanges

Then searching for the existing item and creating a new one, both of which use the same manufacturer not yet saved

var ItemProcesso = GetItem(1)
ItemProcesso.Fabricante = fab;

var adc = new Adicao()
adc.Fabricante = fab;
ItemProcesso.Adicao = adc;

Now before saving I need to know which fields are being changed from ItemProcess then and it is at that moment that the error below occurs:

var entryPro = Context.Entry(entity);

Error: Conflicting changes to the role 'Producer_Product_Target' of the relationship 'Portal.Inf.Data.Context.ProviderItem' has been detected.

Now if you comment on one of the 2 below the problem does not occur.

ItemProcesso.Fabricante = fab;
adc.Fabricante = fab;

NOTE: If I pass the ManufacturerId (object already saved) the problem does not occur

Does anyone know if there is any way to perform this operation without error? Tip suggestions are also welcome.

    
asked by anonymous 14.08.2018 / 22:56

0 answers