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
|
I have the below attribute in my UserProfile domain object private readonly EntityCollection<Favourite> favourites = new EntityCollection<Favourite>(); And the following in Favourite domain object private int _userProfileId;
myProfile.Favourites.add(myFavourite); upon running Repository.CompleteUnitOfWork(); I get a The INSERT statement conflicted with the FOREIGN KEY constraint error and looking at the SQL the Inserts for the Favourite s happen before the UserProfile. The are several ways I can add the Favourite to Favourites. Which way is the best for LightSpeed so I can avoid this FOREIGN KEY constraint error. Or do I need to persist the UserProfile before adding to the Favourites collection?
Johannes |
|
|
LightSpeed handles correct ordering of generated SQL statements. Are you adding the UserProfile to the Repository through Repository.Add? Cheers, Andrew. |
|
|
Hi Johannes, I've put together (see attached) a quick test app with your UserProfile->Favorites model. Can you take a look and let me know how you get on? Cheers, Andrew. |
|
|
Hi Andrew, I'm still looking at this issue. As far as I can see I've done everything just like in your example but it's still not working for me. My user profile has two address attributes and I've found that if I remove those the Favourites attribute and it's relationships work fine. I've tried to replicate this in the little sample you sent me. I can add one address attribute and it works but I'm having trouble making the second one work. The error I'm getting is Mindscape.LightSpeed.LightSpeedException: Could not determine the reverse association of [UserProfile.Address2 (Address)]. How does LS know which reverse association is for which address attribute? (See OneToManyMyExample.zip in Model.cs Line 83). In "LS Sample.zip" I have all the objects and DB scripts as I have them in my solution. In this sample when I comment out all Address associations the 0..* to UserLikes aka Favourites works fine? Sorry to dump this all on you but I just can't spot the error. I'll email the two .zip's shortly.
|
|
|
Hi Andrew, I've come accross something that my help you help me :) In my Test I've swapped the order order of creating my child attribute. This is what I found. Favourite f1 = new Favourite; Address a1 = new Address; UserProfile p1 = new UserProfile; This works BUT the following doesn't Address a1 = new Address; Favourite f1 = new Favourite; p1.Address = a1; p1.Favourites.add( f1 ); p1.Favourites.add( f2 ); p1.Favourites.add( f3 ); The only affect as far as I can see this has is that in the first the Favourites get the first set of keys from the key table. Maybe this has something to do with how LS builds the querries.
Hope this helps. Johannes |
|