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 - I have seen this mentioned, but not in this context. I am trying to demo the latest nightly build of LightSpeedExpress using VS 2010 C#.NET (3.5) and SQL 2008 Express.
I first created the lightspeed model, then dragged 5 tables from the Northwind database, as follows: Order, OrderDetail, Product, Category and Customer When I tried to save this, I got the folowing error: Column ProductID is mapped multiple times in entity Orderdetail
What gives? Thanks, Dave |
|
|
This means your model would result in multiple fields being generated in the OrderDetail class which would all try to load from and save to the same column. LightSpeed doesn't handle multiple fields all sharing the same database column, so it raises a warning if it thinks this is going to happen. A possible cause is that OrderDetail has an association to Product (named Product), and also has an explicit ProductID amongst its properties. Could this be the case? If so, the explicit ProductID is not required because the association implicitly creates a ProductId property as well as the Product association property itself. If that's not the case, could you post the .lsmodel file so we can understand what's causing the warning? Thanks! |
|
|
I guess I'm not following your logic here. All the tables have explicit foreign key fields that reference other tables, plus an association that is named after th referenced table... In the case of OrderDetail, the problem may be caused due to the fact there is a multiple-field Identity (ProductId and OrderId). I notice that in the designer, the explicit foreign key fields are hidden on the other tables, but not on OrderDetail. I will attempt to post the .lsmodel file, if I can figure out how to do that you will be able to look at it. If not, you can easily replicate it on your end by dragging the indicated tables from the Northwind database that ships with SQL Server 2008 and trying to save that. All I have done is create the solution, add a LightSpeed model, and drag the tables onto the design surface.
Thanks, Dave
|
|
|
<?xml version="1.0" encoding="utf-8"?> |
|
|
Ivan - I think I know what the confusion is, but I don't know how to get around it. OrderDetails has 2 "foreign key" fields, OrderId and ProductId. OrderId is used in the relation with Orders, ProductId is used in the relation with Products. So far, so good. However, those 2 fields taken together are also used as the Identity of the OrderDetails table. I think the way to fix this is to create a new Identity column (OrderDetailId, for example) and stop using the ProductId and OrderId as double-use columns. However, this would break existing stored procedures and such in a database that I have no control over. Is there another way to work around this? Since I am just trying this out I will grab some different tables from the Northwind database for now that don't have this problem, but this can happen in the real world. What is the solution?
Thanks, Dave |
|
|
Hi Dave, Your analysis is spot-on: the conflict is between the OrderId field in the primary key and the implicit OrderId field resulting from the Order association. The solution is to use a recent nightly (if you're not already doing so) and to apply the ForeignKeyFieldAttribute to the association. Unfortunately, the designer doesn't support this at the moment, so you'll need to set the association's Generation property to None, and recreate the EntityCollection and EntityHolder fields and properties in the partial classes, then apply ForeignKeyFieldAttribute by hand: [ForeignKeyField("Id.OrderId")] See http://www.mindscape.co.nz/forums/Post.aspx?ThreadID=2990&PostID=9499 for more info and http://www.mindscape.co.nz/forums/Post.aspx?ThreadID=3147&PostID=10435 for a worked example (in the context of a through association, but should still make sense in your context). I'll see if I can get ForeignKeyFieldAttribute support added to the designer so you won't need to muck around with handwritten code. |
|
|
Just to let you know that nightly builds beginning 18 May 2010 (available from about 1500 GMT) will allow you to apply ForeignKeyFieldAttribute via the designer instead of needing to break out into handwritten code. Select the OneToManyAssociation arrow and enter the desired path in the Key Property Reference setting (yes, I know the name is a bit enigmatic, we didn't want to call it Foreign Key Field or whatever because that would encourage people to fill it in when it wasn't required or desirable). Thus, in your case, you would select the Order arrow and set KPR to Id.OrderId. As always, please let us know if you run into any bugs or issues. |
|
|
Thanks! That seems to work as advertised. If I happen to run into problems with tis feature I will let you know, but it seems to work just fine for the moment. Dave Newman
|
|