This seems like an Inverse = true problem. You should be able to
delete a child without affecting the parent. Your collection should
have this attribute:

[HasMany(Inverse = true)]

This makes the child responsible for persisting and updating itself,
not the parent. Thus, you can delete children without touching the
parent. Keep in mind though that if you do use Inverse = true, you'll
have to set the child's parent as well, or else it'll save a null
value in the database for the parent ID. If you just want to use
collection.Add(child) without also using child.Parent = parent, then
you can't use the inverse.

Come to think of it, once the parent object gets saved, doesn't it
become persistent? The parent should know how to delete itself once
you save it.


On Jan 9, 3:20 pm, TimmyC <[email protected]> wrote:
> I've been trying to get a successful test for Parent Child
> relationship cascade delete but was failing again and again...
>
> Here is the failing test:
>         [TestMethod]
>         public void TestParentDeleteCascade()
>         {
>             //Setup a parent
>             Parent parent = new Parent();
>             parent.Name = "Luke, I am your father.";
>             parent.Save();
>
>             Child child = new Child();
>             child.Name = "Noooo";
>             child.Parent = parent;
>             child.SaveAndFlush();
>
>             //Not null exception thrown here
>             parent.Delete();
>
>             Assert.IsFalse(Child.Exists(child.Id));
>         }
>
> Here is the working test:
>         [TestMethod]
>         public void TestParentDeleteCascade()
>         {
>             //Setup a client
>             Parent parent = new Parent();
>             parent.Name = "I am your father.";
>             parent.Save();
>
>             Child child = new Child();
>             child.Name = "Noooo";
>             child.Parent = parent;
>             child.SaveAndFlush();
>
>             Parent newParent = Parent.Find(parent.Id);
>             newParent.Delete();
>
>             Assert.IsFalse(Child.Exists(child.Id));
>         }
>
> Moral of the story: Be careful that the current object your using is
> the most up to date version of that object....
>
> Sometimes it's just not your night.....
-- 
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