This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, Just wondering if the tests below can be passed in LightSpeed or not. public void AddingPostAssignsBlog() {
b.Posts.Add(p1); // Not this: b.AddPost(p1)
Assert.AreSame(b, p1.Blog);
}
public void AddingBlogAssignsPost() {
Blog b = new Blog(); Post p1 = new Post(); Post p2 = new Post(); p1.Blog = b;
Assert.AreEqual(2, b.Posts.Count);
The actual question is if the navigation in associations is stateful (when you change something - it gets reflected on all dependants)? And how LightSpeed does behave in this case (when trying to save all objects):
Thanks, |
|
|
Hi Dmitriy, Your first two tests will pass. Adding an entity (e.g. a Post) to another entity's association collection (Blog.Posts) automatically wires up the backreference (Post.Blog); and setting the backreference automatically adds the child to the collection of the new parent (and removes it from the collection of the previous parent if it had one). In your final scenario, I'm not 100% sure because there are a couple of typos which make me unsure about what is a Post and what is a Blog, but I think what you are asking about is something like this: Blog blog1 = new Blog(): If that's the scenario, the answer is last one wins. blog2.Posts.Add implicitly removes post from blog1.Posts, and sets post.Blog to blog2. So you would end up with blog1 containing no posts and blog2 containing one post. If I've misunderstood, please let me know! |
|