Yes they do, because multiple people can share one address (like a
household of people).

I tried inverse = true on the HasMany attribute, but it's the same
result, 2 addresses created with one that's orphaned.


On Jan 8, 10:12 pm, Krzysztof Koźmic <[email protected]>
wrote:
> Does your address really needs to be an entity?
>
> Most of the time it's really a component, which means you wouldn't have
> such problems.
>
> Otherwise, set inverse = true.
>
> On 2010-01-09 08:55, DanielT wrote:
>
> > 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.


Reply via email to