I have two entities, Person and Address. Here they are simplified:
------------------------------------------------------------
[ActiveRecord]
public class Person : ActiveRecordLinqBase<Person>
{
[BelongsTo(Cascade = CascadeEnum.All]
public Address Address { get; set; }
}
[ActiveRecord]
public class Address : ActiveRecordLinqBase<Address>
{
}
------------------------------------------------------------
I'm running the following code:
------------------------------------------------------------
// Add initial person and address
var person = new Person();
person.Address = new Address();
person.Save();
// Change address
person.Address = new Address();
person.Save();
------------------------------------------------------------
After running the first save, I get one Person and one Address saved
in the database, which is the expected behavior. However, after the
second save, I get one Person and TWO addresses, one of which is
orphaned. In the object-oriented world, this orphaned object would get
garbage collected, but in the database world, there's nothing that
says this Person object can't exist by itself. Semantically, it also
makes sense, since the Address belongs to the Person rather than the
other way around. However, in my object model, Address belongs to a
Person and shouldn't exist without one.
Does this mean I have to manually 'garbage collect' it? I would need
to introduce an 'ICollection<Person> Addresses' in Address and use
'Person.Queryable.Where(x => x.Addresses.Count == 0)' to determine
whether it should delete itself or not. However, can Castle do this
for me automatically?
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" 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/castle-project-users?hl=en.