Composite Key with EF 4.1 Code First -


I am trying to explain how to achieve the overall key using the EF code first 4.1 RC

Currently, I am using [Key] Data Annotation, but I am unable to assign more than one key.

How would a composite key specify?

Here is my example:

  public class activity type {[key] public int activity id {received; Set; } [String Lang (50, error message = "activity name should not exceed 50 characters")] Public String ActivityName {get; Set; }}   

I must also have a key of "activity name". Of course, I can code around it, but this is not a good database design.

You can see both the code> key activity ID with annotation and You can use the Fluid API as described by ActivityName properties or as described by @Telloner.

Edit:

This should work - composite key with annotation needs a clear column command:

  public class activity type { [Key, column (order = 0)] public int activity id {get; Set; } [Key, column (order = 1)] [required (error message = "A activity name is required"]] [string string (50, error message = "activity name should not exceed 50 characters")] Public String ActivityName {get; Set; }}    

Comments