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 am trying to get an example of a ThroughAssociation working, but have only found fragments of documentation on it and have not been able to get them to work.
Here is what I am trying to do. I am trying to abstract the many-to-many relationship between people and addresses so that I can go directly from a person to their list of adddresses rather than through the linking table first. So my data model looks like (Persons --> PersonAddresses --> Addresses) so I want the Person class to have a property called Addresses that expose the Address directly.
Here is what I have done so far:
--- Person Class ---
Private ReadOnly _personAddresses As New EntityCollection(Of PersonAddress)()
Private ReadOnly _addresses As ThroughAssociation(Of PersonAddress, Address)
Public Sub New()
MyBase.New(False)
Initialize()
_addresses = New ThroughAssociation(Of PersonAddress, Address)(_personAddresses)
End Sub
Public ReadOnly Property Addresses() As ThroughAssociation(Of PersonAddress, Address)
Get
Return [Get](Of PersonAddress, Address)(_addresses)
End Get
End Property
---- End of Class ----
I am getting a "Path component [Addresses] not found in type [Persons]" error when trying run a simple linq query against this like this:
Dim oPerson = (From P In UOW.People Where P.Addresses.Count > 0).First
Is my implementation of this wrong?
|
|
|
Whoa... my formatting was all lost when I posted that (using chrome).
|
|
|
I think your implementation of the through association is correct. The reason you are getting this error is that we do not support queries through through associations -- the TA is a helper that simplifies getting and updating the many-to-many association without having to explicitly work with the intersection entity, but it is not used in resolving queries. (We have this on the wish list!) The workaround for this is to flip the query: Dim oPerson = (From pa In UOW.PersonAddresses Select pa.Person).First() One caveat: although this will work fine for a First() scenario, if you were returning all results then you would get duplicate entries for people with more than one address. We do not currently support server-side Distinct() so you would need to deduplicate this on the client side using ToList or AsEnumerable: Dim oPerson = (From pa In UOW.PersonAddresses Select pa.Person).ToList().Distinct(idComparer). You may also find that the query above returns Persons in a different order from a direct Person query, so if ordering is critical you may need to add an Order By clause. |
|
|
Will this feature make it into 3.0? I sure hope so.
Also, we are heavily evaluating Lightspeed against L2S and EF to try and determine what will be our standard for development and have a few features missing that we will need, such as Distinct and Joins. Do you have a list of which features are missing such as these and when the plan to be implemented? We need to know so we can make a decision, and also support our legacy code that uses L2S heavily.
|
|
|
We've discussed the feasibility of supporting querying on ThroughAssociations in LightSpeed 3 and I'm afraid we don't think it's going to happen. The way that ThroughAssociations are implemented makes it a bit tricky for us to resolve them into queries. That said, there are a couple of standard patterns so we might be able to look at this in the post-3.0 timeframe. We don't have a detailed feature comparison between LightSpeed, Entity Framework and LINQ to SQL. There's a high-level comparison at http://www.mindscape.co.nz/products/lightspeed/comparison.aspx but this doesn't go down to the detail of particular SQL or LINQ operators such as Distinct and Join. We do expect the LINQ implementation in 3.0 to be much more comprehensive and we would welcome any sample queries that are representative / critical for you so that we can add them to our LINQ test suite. |
|