Problem using self tracking objects, the changes always get saved even if I dont want to. RRS feed

  • Question

  • Hello everybody. I'm just begining to work with entity framework and self tracking objects so I don't understand exactly everything. Here at work we are trying to implement an DDD n-layered architecture but i'm having problems with the use of self trackin objects: The changes I made to an instance of an object always get saved to de database even if I don't need to. Example:

     public void ActualizaInscripcion(EGestionPostulante postulante, string rutConyuge, string digitoConyuge)

             IConsultableUnidadDeTrabajo unidadDeTrabajo = (IConsultableUnidadDeTrabajo)UnidadDeTrabajo;

             IObjectSet<SOLICITUD> solicitud = unidadDeTrabajo.CrearSet<SOLICITUD>();
                   var query = from s in solicitud
                         where s.SOL_ID == postulante.Identificacion_Persona.SOL_ID
                         select s;

             SOLICITUD solantigua = query.FirstOrDefault<SOLICITUD>();

             SOLICITUD SOLNueva = new SOLICITUD
                   IDO_ID = solantigua.IDO_ID,
                   ENT_ID = solantigua.ENT_ID,
                   ENT_ID_REC = solantigua.ENT_ID_REC,
                   REG_ID = solantigua.REG_ID,
                   FNC_ID = solantigua.FNC_ID,
                   SOL_RCN_FEC = solantigua.SOL_RCN_FEC,
                   SOL_ING_FEC = solantigua.SOL_ING_FEC,
                   SOL_USR_REC = solantigua.SOL_USR_REC,
                   SOL_USR_DIG = solantigua.SOL_USR_DIG,
                   SOL_FOL = solantigua.SOL_FOL,
                   SOL_MOD = solantigua.SOL_MOD,
                   SOL_TIP = "5",
                   SOL_EST = solantigua.SOL_EST,
                   SOL_ARE_EVA = solantigua.SOL_ARE_EVA,
                   IDO_ID_PRY = solantigua.IDO_ID_PRY

              Repositorio<SOLICITUD> repsolicitud = new Repositorio<SOLICITUD>(unidadDeTrabajo);

             using (TransactionScope transaccion = new TransactionScope())



     ok, its a little complex because is in spanish (I'm from Chile). IConsultableUnidadDeTrabajo is UnitOfWork. It contains some methods implemented in the archive to register changes. The object "postulante" is a type "EGestionPostulante". EGestionPostulante is a class that I use as an Entity. I needed to group several entities from my model, so I created that class wich its atributes are the entities I needed to group (I dont know if that is correct by the way). Anyway, the problem is that I only need to insert the new object called "SOLNueva" (type SOLICITUD, a object from my model), but every change made before, even if I didnt register it with ApplyChanges(entity), saves into the data base. In this case all the changes made before to "postulante" (wich is compose of several entities, as I said before). In the end unidadDeTrabajo.RealizarCambios()means makeChanges, it calls the method SaveChanges()). I tried to use "postulante.MarkAsUnchanged()" but it doesnt work. Maybe is wrongly implemented. I dont know. I'm stuck in this. Thank you if you take the time to read this post.

    • Edited by PaulNet83 Tuesday, December 6, 2011 2:37 PM the format is messed up
    Tuesday, December 6, 2011 2:36 PM

All replies

  • You shoudl use "MarkAs" methods before savechanges here:


    I am fish.
    Thursday, December 22, 2011 12:31 PM