The problem is that _modulo
and modulo
are the SAME object. Both variables reference the same object.
What you are doing right now with _modulo = modulo;
is NOT copying modulo
to the new object but instead setting the reference for _modulo
to the exact same point in memory of modulo
. References are equal.
Then, when you call _PermissoesLinxDB.SalvaModulosUser(_modulo);
it is actually trying to save(?) the already existing object, modulo
and throwing an exception because it already exists.
What I think you intend to do is something like the following which is to 1) create a new object, 2) assign the internal values of another object to it, and finally 3) save the new object:
USERS_MODULO _modulo = new USERS_MODULO();
// assign each property from the old object to this brand new object
_modulo.PropertyA = modulo.PropertyA; // obviously, substitute your property names
_modulo.PropertyB = modulo.PropertyB;
_modulo.PropertyC = modulo.PropertyC;
// etc..