Entering keys manually with Entity Framework

Since I prefer attributes, here the alternative for the sake of completeness:

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int Id { get; set; }

Note: This works also in EF Core.

Leave a Comment