I want to generate multiple Id's in entity framework core

时间:2017-08-04 12:18:16

标签: c# entity-framework-core

So my question is: I would like to generate an incremented id on foreign key StudentId, but my gebruikerId is already the primary key with identity enable. and the exception I get is: "Multiple identity columns specified for table 'Gebruikers'. Only one identity column per table is allowed." Which makes sense, but how is it possible to generate multiple Id generation in the same class/superclass.

public class Gebruiker
{
    [ScaffoldColumn(false)]
    public bool Active { get; set; }
    [Key]
    public int GebruikerId { get; set; }
}

[Table("Studenten")]
public partial class Student : Gebruiker
{
    public Student()
    {
        StudentProjects = new List<StudentProject>();
        StudentSkills = new List<StudentSkill>();
        Rapporten = new List<Rapport>();
    }

    //not allowed but I need it.
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 
    public int StudentId { get; set; }
}

0 个答案:

没有答案