If you add DataAnnotations "Key" a new key will be created when you execute "SaveChanges". But if you wanted to bootstrap records into your database, how do you turn off the auto-generate a key feature?
public class Item
{
[Key]
[Required]
public Guid Id { get; set; }
public string Name { get; set; }
}
Use [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] annotation on Id field
public class Item
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
[Required]
public Guid Id { get; set; }
public string Name { get; set; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With