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
|
Is there a known problem with ThroughAssociation where if you query both sides of the many-to-many relationship in the same method that it will return one of the through associations, but not the other? Here's my method code: Penguin penguin = UnitOfWorkHolder.Current.FindOne<Penguin>(1); Lion lion = UnitOfWorkHolder.Current.FindOne<Lion>(1); There's a table in the middle called PENGUINS_LIONS to maintain the through association. If I run each block separately, they return the appropriate through assocation collection. If I run them together, one after the other, the second through association returns a 0 count for penguins. I initially thought this had to do with the CRUD sp support, but I removed that and still see this behavior. Granted, this case may not make alot of sense in real world code, but I was just putting together a demo and ran into the issue. Thanks.
|
|
|
Hmm, we're not seeing that behaviour, so this may be a glitch with load order. Could you send us the definitions of the Penguin and Lion classes please so we can look into this? Thanks! |
|
|
Here ya go.
using System; namespace LightSpeedCombinedSample //Relationships define the associations to other tables #region Delegates #region Constructors //When using a many-to-many relationship, you need to setup the ThroughAssociation when creating the instance so it can properly map across the many-to-many without using the middle class #region Event Handlers //Each private member should have an associated property that is accessed to get the data #region Methods #region Custom Validation }
using System; namespace LightSpeedCombinedSample //Relationships define the associations to other tables #region Constructors //Each private member should have an associated property that is accessed to get the data |
|
|
You may also want this:
using System; namespace LightSpeedCombinedSample //Relationships define the associations to other tables //Each private member should have an associated property that is accessed to get the data #region Methods
|
|
|
Looks like you have a couple of misplaced EagerLoad attributes causing you some grief. I have set up your model and some test data locally here and could see what you were meaning about it not fetching the other side. On investigation, I noticed you had some EagerLoad attributes on the Penguins_Lions entity - these are not required. You also need to make sure that each entity is eager loading the Penguins_Lions, so that this is available when it initializes the ThroughAssociation in the constructor. e.g. On Lions entity: [EagerLoad]
On Penguins entity: [EagerLoad]
On Penguins_Lions: #region Relationships
And that sorts it for me here - let us know how you get on :)
Jeremy |
|
|
Good deal. Let me look at that and see if it helps. On a side note. Should I be able to things like First<> and Where<> on a ThroughAssociation? I get this error when trying: 'Mindscape.LightSpeed.ThroughAssociation<UserGroup,Group>' does not contain a definition for 'First' and no extension method 'First' accepting a first argument of type 'Mindscape.LightSpeed.ThroughAssociation<UserGroup,Group>' could be found (are you missing a using directive or an assembly reference?)
|
|
|
ThroughAssociation<,> is IEnumerable<> so you should be able to use all the LINQ to Objects operators including First and Where, though note that these will run client-side over the collection rather than as a SQL query. Have you done a using System.Linq; to bring the extension operators into scope? |
|