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'm sure there's something simple I'm missing here, but is there any way to map the PK to a field named something other than 'ID'? I'm using an existing DB where the convention was to name IDs <TableName>Id. Cheers, Nick |
|
|
Hi Nick, There are several ways but the best one in your case is to implement INamingStrategy and then set your instance on LightSpeedContext. This allows you to easily express naming conventions in one place. Cheers, Andrew. |
|
|
I'm a bit confused by this too. I have legacy data that follows the pattern below: sample table name: Table1 so for my Table1 entity i would like properties: public int Table1Key { //returns primary key column table1_key } can this be autogenerated?
|
|
|
In addion, My legacy tables can have column names with _id or _key suffix, so the autogenerated foreign key column names become confusing. |
|
|
The earlier responses in this thread are quite old (hmm... looks like forums don't show the year) and things have moved on a bit especially since you are using the designer. You can map the primary key column name using TableAttribute or by specifying Identity Column Name in the designer. If you are dragging and dropping from Server Explorer, and the PK column is not named Id, then the designer should set up the Identity Column Name for you. For one-to-many associations, you can map the foreign key column name in the designer by selecting the association arrow and setting the Column Name. Again, the designer should do this for you if it is working out the associations from a drag-and-drop. The designer names the association for the foreign key column, minus the Id suffix if present. Id is the only suffix the designer strips out, so if your database uses _key as its FK column naming convention, the one-to-many association from Customer to Order will end up with a backreference name of CustomerKey. This will in turn result in the foreign key property itself being generated as CustomerKeyId. The only way around this is to change the backreference name from CustomerKey to Customer. The generated FK property will then be called CustomerId. Sorry, we don't provide a way to change the Id suffix in the generated FK property. If the designer hasn't set up the Column Name for you (to "customer_key") then you can do so by hand to keep the mappings straight. Unfortunately, you mentioned that your Table1-Table2 relationship was one-to-one. Right now, the designer doesn't provide a way to map the column name for one-to-one associations. If you need to customise the mapping of the FK column for a one-to-one association, you will therefore need to write the association in code via the partial classes. (You need to create both ends of the association.) The designer limitation is just down to prioritisation, not any inherent impossibility, so we'd be happy to look at adding one-to-one FK column mapping to the designer for you if that would be useful. |
|