2010/6/9 Eddie <[email protected]>:
> Hi all.
>
> I'm trying to manage collections. I get an error when I use the
> annotation "[Transaction]" in my method.
> The error is
> "A collection with cascade="all-delete-orphan" was no longer
> referenced by the owning entity instance: Cuenta"
>
> My method
>
> [CODE] [Transaction]
> public void AgregarCuenta(int idPersona, string cuenta)
> {
> Persona persona = RepositoryPersona.Get(idPersona);
>
> IList<Cuenta> cuentas = new List<Cuenta>();
> Cuenta cta = new Cuenta();
> cta.Numero = cuenta;
> cta.Saldo = 100;
> cta.Medico = persona;
> cuentas.Add(cta);
>
> persona.Cuentas.Clear();
> persona.Cuentas = cuentas;
I would normally try to make the Cuentas setter private. Then instead do:
foreach (var c in cuentas)
persona.Cuentas.Add(c); // or persona.AddCuenta(c);
(Or in this case, skip the local cuentas and add directly to personas.Cuentas.)
This way the persona is in charge of the collection it owns.
/Oskar
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.