When doing the CodeFirst approach, there are two ways to declare keys and related tables.
public class Person
{
[Key]
public int Id { get; set; }
}
OR
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Person>().HasKey(e => e.Id);
}
Is this a matter of preference or does it make sense to use one over the other? What should be used in a fresh project?
Update: I will have around 8 entities each with around 1-4 relations and I want to allow cascade delete.