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, I have the following situation. I have 2 tables (see below; left out unimportant fields) and would like to link them not via FK-PK but via a different field. The reason is we use IdentityColumn for our tables but need to import data from a different database from time to time where we want to keep all data. Table: Users Table: Meetings Getting a user is no problem. However, if i then do something like: select * from Meetings where Number == <users.Id> Any idea what could be wrong? Cheers, |
|
|
LightSpeed always assumes foreign keys are to the ID (primary key) of the other table. We don't support foreign keys to non-ID fields (it's on the wish list, but we don't do it at the moment and it's not an easy fix). Instead, you'll need to write the lookups by hand e.g. partial class User { I'll see if I can get the designer to report an error when dragging on tables that use foreign keys to non-IDs so that you don't get a confusing and incorrect association inferred for you. |
|
|
Thank you, this worked great! I was unaware that Lightspeed did not support Foreign Keys to non-ID fields. |
|
|
Small follow-up question: now assume Number is a string? Lightspeed has automaticaly added/changed some fields b/c of the relationship but these are of the wrong type. Added/changed fields in Meeting class: I have to fill in NumberId to prevent a FK exception. However in this other situation Number is of type String, not int. Any way I can code around this? Thanks, |
|
|
I just sticked with linking the tables via ouw own defined Primary Keys and still storing the Number in every table. This gives some extra columns, but saves a lot of headaches. Thanks for the first answer, that really helped a lot! |
|