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 Guys, Is it possible to setup a Through Association on a single table, eg I have a Product Table, and each product can have related products which would work both ways. I have tried, but it's not working - before I spend too much time on it, I just wondered if this was possible. Cheers |
|
|
Yes, it is possible -- working for me when I try it. |
|
|
Same as xoozoo, not working 100% for me also (LS build from June). I will try to give more details. I.e we have Position entity/table, and PositionLink entity/table aprox. looking like this: Position entity because of this has 2 collections - PreviousPositionLinks, NextPositionLinks. After creating through association in Position to get all NextPositions as collection, this works fine. Through association for PreviousPositions collection is not working OK.
|
|
|
I took a look at LS source, and am almost sure about above conclusion. The ThroughAssocciation constructor has code like this: |
|
|
Thanks for the info and the diagnosis. As mentioned above, I've tried building a test case for this and it works for me, so I must be missing some difference between your code and mine. If you could provide me with a small console project or NUnit test which demonstrates the problem, I'd be more than happy to look into it! Thanks! |
|
|
Hi Ivan, OK, here is a simple console test, with exact example I tried to explain earlier. I included also a Position Map chart showing connections built between positions in the test program. DDL for building DB is also inside. |
|
|
Ah, excellent -- thanks Marko. I've reproduced and fixed the problem, and the fix will be in the next nightly build (22 October, available around midday UTC). |
|
|
hmmm I am trying to do the same thing, and not getting very far. Here is my setup: Single Entity called "User". With an Through Association on itself. Auto Through Entity property set to "UserFavoriteUser". Source collection called "FavoriteUsers", Target Collection Name "FavoritedBy". I get compilation errors about _userFavoriteUsers & a few other members and properties being defined twice in User entity. Here is what is being created:
#region Relationships [ReverseAssociation("User")] private readonly EntityCollection<Post> _posts = new EntityCollection<Post>(); [ReverseAssociation("User")] private readonly EntityCollection<FavoritePlaces> _favoritePlaces = new EntityCollection<FavoritePlaces>(); [ReverseAssociation("User")] private readonly EntityCollection<UserFavoriteUser> _userFavoriteUsers = new EntityCollection<UserFavoriteUser>(); [ReverseAssociation("User")] private readonly EntityCollection<UserFavoriteUser> _userFavoriteUsers = new EntityCollection<UserFavoriteUser>(); private ThroughAssociation<FavoritePlaces, Place> _places; private ThroughAssociation<UserFavoriteUser, User> _favoritedBy; private ThroughAssociation<UserFavoriteUser, User> _favoriteUsers; #endregion
Any ideas where i am going wrong? Sorry ... i'm a lightspeed n00b.
|
|
|
We have a limitation in the designer that it doesn't support through associations to self. The workaround is to implement the through entity and one-to-many associations in the designer, then to add the through association in the partial class. See http://www.mindscape.co.nz/blog/index.php/2009/09/17/many-to-many-associations-in-the-lightspeed-designer/ or http://www.mindscape.co.nz/blog/index.php/2010/10/19/many-to-many-associations-from-designer-to-database/ for an illustration of using an explicit through entity and one-to-many associations in the designer. I'll assume that your one-to-many association collection names are UserFavouriteUsers and UserFavouritedByUsers. Then, in the partial class, add the following code: private ThroughAssociation<UserFavouriteUser, User> _favouriteUsers; public ThroughAssociation<UserFavouriteUser, User> FavouriteUsers { You then add similar code for the FavouritedBy through association, but this time wrapping the UserFavouritedByUsers one-to-many association instead of UserFavouriteUsers. See http://www.mindscape.co.nz/Help/LightSpeed/Help%20Topics/LightSpeed/ThroughAssociations.html for more info about what is going on here. I'll take a look at fixing this designer limitation, or at least producing a more meaningful message. |
|
|
There'll be a fix in the next nightly build (available around 1200 UTC) which will enable through associations to self in the designer, but only expressed using auto through entities. This shouldn't be a limitation for greenfield applications unless you need to store additional data on the link (e.g. the time when the user favourited the other user). Please take it for a spin and let us know if you run into any problems with it. |
|