I'm creating a POCO model to use with entity framework code first CTP5. I'm using the decoration to make a property map to a PK column. But how can I define a PK on more then one column, and specifically, how can I control order of the columns in the index? Is it a result of the order of properties in the class?
Thanks!
You can specify the column order in the attributes, for instance:
If you are using the
Find
method of aDbSet
you must take this order for the key parameters into account.To complete the correct answer submitted by Slauma, you can use the HasKey method to specify an order for composite primary keys as well:
If, like me, you prefer to use a configuration file you can do that in this way (based on Manavi's example):
Obviously you have to add the configuration file to your context:
Use as a anonymous object: