Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

251
Views
Unable to determine composite primary key ordering for type

{"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; }        
}

enter image description here

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?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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!

about 4 years ago · Santiago Trujillo Report

0

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

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!