Question: How do you resolve the Entity Framework Error: Unable to track an entity of type "Model Class Object" because primary key property 'id' is null?
Login to See the Rest of the Answer
Answer: Make sure you mark the Id of your class Model as the primary key using System.ComponentModel.DataAnnotations . This lets the Entity Framework know that the column is a primary key therefore it should have a value generated on the database site.
using System.ComponentModel.DataAnnotations;
namespace FolderYourModelsAreLocated.Models
{
public partial class YourModelName
{
[Key]
public string id { get; set; }
}
}
Question
How do you resolve the Entity Framework Error
Unable to track an entity of type "Model Class Object" because primary key property 'id' is null?
Answer
Make sure you mark the Id of your class Model as the primary key using System.ComponentModel.DataAnnotations . This lets the Entity Framework know that the column is a primary key therefore it should have a value generated on the database site.
using System.ComponentModel.DataAnnotations;
namespace FolderYourModelsAreLocated.Models
{
public partial class YourModelName
{
[Key]
public string id { get; set; }
}
}