I would like to create a base model with some common fields for all tables, like CreatedBy
and ModifiedBy
, but I don't want to add the key to that base model.
public abstract class BaseModel
{
public string CreatedBy { get; set; }
public string ModifiedBy { get; set; }
}
public class Student : BaseModel
{
[Key, Column(Order = 0)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string FirstName { get; set; }
}
I am getting this error message
The derived type cannot have KeyAttribute on property 'Id' since the primary key can only be declared on the root type
.
I am using Entity Framework Core 2.