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
|
Ok simple question is: how does this work? unsure of the semantics for setting up composite primary keys, any help?
|
|
|
Define a struct to represent the type of the key, then inherit from Entity<MyKeyType>. For example, here's an entity with a composite key consisting of a ProductId and a LanguageId: public struct InternationalProductId |
|
|
thanks Ivan,
is there any support for this in the lightspeed designer in 3 or does it have to be a hand coded entity?
Cheers
Owen
|
|
|
Yes, it is supported in the designer. If you are doing database-first, which is our assumed scenario for composite keys, then dragging a table with multiple primary keys onto the design surface will create multiple identity properties. If you are doing model-first, our first recommendation is of course not to use composite keys! But if you really need to do CKs in a model-first scenario, then you will need to go to the LightSpeed Model Explorer, locate the entity in the tree view, right-click and choose Add New Identity Property. (Once you've put an entity into "composite key mode" by doing this, you can skip this little dance and right-click on the entity surface to add further keys.) In both cases, this will result in generating a struct called XxxId (where Xxx is the name of the entity) and declaring the entity type as Entity<XxxId>. Note that we do NOT generate overrides for Equals and GetHashCode so you may want to add overrides for these via the partial class. |
|