Reputation: 1361
{"Unable to determine composite primary key ordering for type 'Conference_Project.Models.Login'. Use the ColumnAttribute (see http://go.microsoft.com/fwlink/?LinkId=386388) or the HasKey method (see http://go.microsoft.com/fwlink/?LinkId=386387) to specify an order for composite primary keys."}
[Table("ConferenceLogin")]
public class Login
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long confid { get; set; }
[Key]
public string emailID { get; set; }
[Key]
public string registration { get; set; }
[Key]
public long regNo { get; set; }
}
Version Used : EntityFramework.6.1.3 And MVC5
I want unique value for this (emailID
, registration
, regNo
) for that
set all as primary key then EntityFramework showed error
how to use multiple primary key with EntityFramework?
Upvotes: 15
Views: 18460
Reputation: 306
Although I'm not sure as to the underlying logic why this error occurs, I did have the same issue with a project I was working on for class. What worked for me was to add a Column(order) decorator to the Key tag turning
[Key]
into
[Key, Column(Order = n)]
where n is the 0-based index of the key in question.
In this light, your class should look like the following:
[Table("ConferenceLogin")]
public class Login
{
[Key, Column(Order = 0), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long confid { get; set; }
[Key, Column(Order = 1)]
public string emailID { get; set; }
[Key, Column(Order = 2)]
public string registration { get; set; }
[Key, Column(Order = 3)]
public long regNo { get; set; }
}
Hope this works for you as well as it did for me!
Upvotes: 29
Reputation: 1
To set that registration column as primary key, you have to set the data type nvarchar(50),. nvarchar(128) will not allow you to make it primary key
Upvotes: 0