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've done a bunch of reading here in the forums, and here: http://www.mindscape.co.nz/blog/index.php/2009/12/22/composite-keys-in-lightspeed-3/ For example, take the ASP.NET Membership tables: AspnetUser AspnetRole AspnetUsersInRole
From what I saw in previous posts here, I should be able to just drag those 3 tables to the LS designer, and everything should work. However, when I try to reference things later on: from y in UnitOfWorkScope.Current.AspnetUsersInRoles I get the dreaded error:
|
|
|
Looking at the UsersInRoles table this appears to be because UserId is a foreign key as well as part of the primary key. (Ditto RoleId.) LightSpeed doesn't really handle this scenario at the moment. To dive into the detail, I think what's happened is that the designer has created an association for the FK. This results in the AspnetUsersInRole entity having two things mapped to the UserId column: the FK (UserId) and part of the ID (Id.UserId). Since LightSpeed can materialise a column only once, it "spends" the UserId column on Id.UserId, and has nothing left when it needs to populate the UserId FK field. The workaround is to remove the association, and manually implement methods or properties that perform the same function through explicit queries e.g. partial class AspnetUsersInRole { I haven't tested this strategy with LINQ queries that need to traverse such "fake" association properties -- let us know if you run into issues. |
|
|
It doesn't look like that's going to work. The join blows up: from ur in AspnetUsersInRoles with: Join.ExtractJoinsForJoinCriteria (LinqQueryPlanExpression plan, IAttributePathExpression criteria, Type entityType, String aliasOverride) The following query throws an exception: from ur in AspnetUsersInRoles
|
||
|
|
Thanks for reporting this -- we've reproduced these issues and will look into getting you fixes. |
|
|
Hi Ivan, Any luck with this one? Thanks. |
|
|
I've implemented projection and join support for fields within a composite key (and other value objects), which should handle your explicit queries though it doesn't address the broader issue of columns that are foreign keys as well as being part of the identity. This will be in nightly builds dated 12 Mar 2010 and above. Please let us know if you still see problems. (My test cases for this were relatively simple so there may be edge cases I haven't covered, though I think it should suffice for the models you're describing.) |
|
|
Works wonderfully for the schema here. Definitely nice to be able to get this part of my app working! Major kudos to you and the team once again. |
|
|
Hello Dan, I've now implemented experimental "native" support for composite keys where columns within the CK are foreign keys. Please see http://www.mindscape.co.nz/forums/Post.aspx?ThreadID=2990&PostID=9499 for details. Not suggesting you should change what's working for you now, but I thought I'd let you know just in case. |
|