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
|
Hello guys Thanks in advance |
|
|
Hi Greg, Not sure what you mean by a "loose association." A LightSpeed association does have to be backed by a key field/column which contains the Id of the associated entity. That column doesn't have to have a foreign key constraint in the database -- if it doesn't, then the designer won't infer the association, but you can still create the association manually. If this is your scenario, let us know and I'll post a walkthrough. If your lookup key doesn't match the Id of the associated entity, but instead matches some other unique column, you can still perform lookups in the partial class using LINQ or query objects: partial class House { You can't represent this in the designer though. |
|
|
Thanks for rapid answer.
"That column doesn't have to have a foreign key constraint in the database -- if it doesn't, then the designer won't infer the association, but you can still create the association manually. If this is your scenario, let us know and I'll post a walkthrough." Yes please. Post me a walk through. Thanks again. |
|
|
Okay, I'm going to assume you have two tables, Customer and Order. Each has a single identity column which I'll assume is called Id. Furthermore, Order has a CustomerRef column which contains the Id of the customer the order is for, but which does NOT have a foreign key constraint in the database. When you drag these two tables onto the designer, you'll see two entities, Customer and Order. The Order entity will have a CustomerRef property (amongst others). There will be no association between them because there was no foreign key constraint in the database. The first thing we need to do is set up the association. Open the toolbox, select the OneToManyAssociation tool, and drag a line from Customer to Order. This creates an association in LightSpeed between the two. You will see that at the Order end, the association is named Customer (i.e. there will be an Order.Customer property). LightSpeed defaults to assuming that the backing column for the association will be CustomerId (the name of the association plus "Id"). Since I've assumed that the backing column is actually named CustomerRef, I need to override this default. To do this, select the arrow you just created, go into the Properties grid, find the Column Name setting, and enter CustomerRef in there. This leaves us with one more thing to do. At the moment, the CustomerRef column is mapped to both the CustomerRef property and the Customer association. LightSpeed can't map one column to two places. So you need to just delete the CustomerRef property from the Order entity. If you need to access this value, don't worry, it is still mapped, but it is named CustomerId (because in LightSpeed the backing field for an association is always named XxxId, even if it is mapped to a different column). With these changes in place you should be good to go! |
|
|
Sorry but no success.
CutPiece (Customer)
When using i got the error, Operator '==' cannot be applied to operands of type 'System.Guid' and 'string', it seems that it still using the ID (guid)? I also tried to do a LINQ for this to tables without any relations, just as two free tables: var query = from cutpiece in UnitOfWork.CutPieces ".. [LightSpeedException: Query Error: Could not find field [Key] on model .." In this case the grouping a think is involved in someway.
Best regards
|
|
|
Looking at your tables this looks more like you want to match to a non-identity column. To use a LightSpeed association, your 'foreign key' MUST refer to the Id of the other table. Since CutPatternID is a varchar and the Id of the other table is a GUID, I don't think this can be the case for you. I'm guessing you actually want to match CutPatternID to CutPatternID. As previously mentioned, this is not possible in the designer -- it can only be done in the partial class (see http://www.mindscapehq.com/forums/Post.aspx?ThreadID=4673&PostID=16647, second paragraph). In your case something like: partial class CutPiece { partial class CutOption { |
|