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, |
|
|
Hi Chris, ThroughAssociations provide essentially the property you describe. If you have Project, User and ProjectUser entity classes, then you can create Project.Users and User.Projects properties using a ThroughAssociation, and add, delete and update using those properties. Have a look in the help file under Help Topics > LightSpeed > ThroughAssociations for a bit more info. You're right that there are limitations on querying across ThroughAssociations. These don't stop you doing the query, you just have to explicitly go via the through collection (i.e. you have to mention ProjectUsers in your query). Also, the designer doesn't yet provide a way to declare ThroughAssociations -- it can only create the through entity class -- you have to add the ThroughAssociation field and properties in the partial class. I think most of the other issues you've noted from browsing the forums have been resolved (though if the documentation is still not clear enough we would certainly welcome feedback). On the WCF front, there's a sample at http://www.mindscape.co.nz/forums/Thread.aspx?ThreadID=1363, though support in the core product has moved on since then -- see the posts about DTOs on the blog. Hope this helps -- please let us know if you have any further questions. |
|
|
Thanks for the quick reply. I'll start playing with it. |
|
|
Ok, I'm slow. My mind apparently isn't working because I can't figure this out. It's a simple newbie question and I feel stupid for asking, but I've played with everything that comes to mind. Here is the M-M layout Tables: Category : Each category has multiple Flashcards Flashcard: Each flashcard can belong to multiple Categories JoinCategoryFlashcard: the join table containing the ID of each of the above, in this case GUIDs
All I want to do is be able to dump every flashcard for every category. I'm stupid and can't figure it out. Here is what I am trying ( the Context is up and working, I can dump Categories fine): Using uow As Mindscape.LightSpeed.UnitOfWork = _cxt.CreateUnitOfWork
How do I use the ThroughAssociation to actually get access to the other side of the Join? How do I loop through the flashcards for each category using the through association. For that matter how do I "associate" the ThroughAssociation with a particular Category. Thanks in advance BTW - PLease no RTFM, I have. I suspect the problem is that I am having some lapse in my ability to translate C# to VB.NET. Although... |
|
|
Okay, just to restate so we can be sure I have understood, we have three classes (and three tables) here: Category Category has a one-to-many association to JoinCategoryFlashcard, and Flashcard has a one-to-many association to JoinCategoryFlashcard. Now create partial classes for Category and Flashcard. (If you're not using the designer, but writing the classes by hand, you can do this directly in the main class definitions.) I'm not a native VB speaker, so pardon any errors, but this will look something like this: Partial Class Category (I'm only going to do the Category end: the Flashcard end is symmetrical.) Now you need to add the ThroughAssociation field to the partial class: Partial Class Category Finally, you need to add an accessor property so you can get at the through association. I'm going to lazy-initialise this, which is a bit more complicated, but avoids some eager-load issues and is more VB-friendly:
Partial Class Category There are a couple of important things here, one fairly blatant and one a bit more subtle. The blatant one is that our Flashcards property is wrapping the Category's JoinCategoryFlashcards member collection. In your code sample, you are creating a free-floating EntityCollection(Of JoinCatFlash), and wrapping your ThroughAssociation around that. Your _flashJoin EntityCollection(Of JoinCatFlash) is a random New (and therefore empty) collection, whereas Category.JoinCategoryFlashcards is a real, database-backed collection that has been properly wired up by LightSpeed. The ThroughAssociation over the empty, disconnected collection has no way of knowing that it's meant to be referring to Cat.JoinCatFlashes. The subtle one is that our ThroughAssociation must be constructed over a *loaded* EntityCollection. By default, EntityCollections are lazy. They are loaded only when you try to get their contents. Hence, in our New expression, we must refer to the JoinCategoryFlashcards *property*, not the _joinCategoryFlashcards *field*. The latter, unless it is marked EagerLoad, may be empty and uninitialised. By referring to the property, we force LightSpeed to initialise it and wire it up before it attaches the ThroughAssociation to it. Hopefully this helps makes things clearer. The ThroughAssociation is associated with a particular Category because it is an instance member field and property of the Category class, not a local variable. Accessing and enumerating the Flashcards for a Category is much like a normal collection: Dim funnyFlashcards = funnyCategory.Flashcards Dim cats = uow.Find(Of Category)() Once again please forgive any mangling of VB.NET syntax -- I hope even this garbled version will be a bit easier to translate than C#! Please let us know if this helps or if you still have questions. |
|
|
Once again, thanks for the fast response. I will start playing with it right away. In between expirementing with this issue, I have really liked it so far!
BTW - add one vote for adding this to the automagically generated code.
thanks again, WCM |
|