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'm trying to link up to an external system in SQLSever2005. There is a table linking the Accounts table with the Usergroups table that contains only the 2 columns with the references to each table it links to with no index of it's own. I just cant get this to work, does not matter what I try, many2many links, a loose table that I query with a where clause, I just cant get it to work..... It either crashes or the one column always comes back as a "1" and the opther is correctly filled.
Help pls... Here is the create statement for the table in question.
regards Anthony
USE [ANTacc] |
|
|
A through entity is still an entity and must have an ID. In LightSpeed 2.x, this means your through table must have a separate identity column. In LightSpeed 3.0 RTM, you could map your two composite key columns to a composite ID type, but we didn't support associations where the foreign keys were attributes of the ID type. In LightSpeed 3.0 nightly builds, we do support associations keyed on attributes of composite ID types, but you have to perform some additional markup (which can't be done in the designer). If you control the database, the simplest solution is to add an ID column to the through table, and make the ID column the PK. If you have to stick with the existing database schema, see http://www.mindscape.co.nz/forums/Thread.aspx?PostID=8129 and http://www.mindscape.co.nz/forums/Post.aspx?ThreadID=2990&PostID=9499 (and you will need to install a recent nightly build of LightSpeed 3). |
|
|
I have downloaded the latest version, still cant get it to work, I'm just after a simple example of howI can perform this, the 2 threads you give here dont give me a simple readable understandable example of how I can achieve this. I still cant get it to work, please provide me with a simple example of how I can achieve this. Thx Anthony
|
|
|
The key piece of magic is in the through class, where you need to use ForeignKeyFieldAttribute to say that the FKs are part of the PK rather than separate fields. Here's my through class in full: public class UserGroupMember : Entity<UserGroupMemberId> Note two things: * The through class Id type is UserGroupMemberId. I'll include the definition of this below, but basically this represents the composite key -- it's a two-member struct with UserGroupId and MemberId fields. * The EntityHolder association fields are decorated with the ForeignKeyField attribute, with a path that traverses into the Id and identifies a member of the UserGroupMemberId struct. Unlike a normal to-one association, there's no separate foreign key field in the class definition -- no int _memberId for example. Everything else is standard LightSpeed associations. So with that highlighting out the way, the full code should be pretty familiar: public struct UserGroupMemberId And here's the SQL (slightly edited for clarity, apologies if any typoes sneak in): CREATE TABLE [dbo].[UserGroup]( CREATE TABLE [dbo].[Member]( CREATE TABLE [dbo].[UserGroupMember]( I inserted two records into UserGroup, with Ids 1 and 2, and two into Member, with Ids 11 (Alice) and 12 (Bob). Then in UserGroupMember I created records for 1 -> 11, 1 -> 12 and 2 -> 12. And here's the test that exercises it: [Test] Let me know if you need any more info. |
|
|
Thank you, It's clear and I understand it :)
I have 1 other problem. when I use the [ForeignKeyField( (Mindscape.Lightspeed.Dll version: 3.0.789.12667 2 or 3 days old) I get the following error:
[ForeignKeyField("Id.UserGroupId")] |
|
|
You've got a reference to the Mindscape.LightSpeed.Migrations DLL as well as to the Mindscape.LightSpeed DLL, and you've done a using Mindscape.LightSpeed.Migrations; instead of (or in addition to) using Mindscape.LightSpeed;. Change the using Mindscape.LightSpeed.Migrations; to using Mindscape.LightSpeed;, or spell out the attribute name in full: [ForeignKeyFieldAttribute("Id.UserGroupId")]. Also, you may not have updated your project references to the nightly build: build 12667 is from December 2009. You need build 13350 or above. |
|