I am trying to access a CosmosDB collection using Entity Framework Core.
My DB has various data, but the primary key is 'id' My Model has a subset of this, but uses 'Id' instead of 'id'.
I have checked that I am able to read/write to a test DB where it includes a copy of 'id' as 'Id'. This causes no issues.
As far as i can read in https://learn.microsoft.com/en-us/ef/core/modeling/indexes it should be possible to set the 'HasName' property.
[DataContract]
[Serializable]
public class TestModel
{
[DataMember]
[JsonProperty("id")]
public string Id { get; set; }
[DataMember]
public string Pid { get; set; }
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TestModel>().ToContainer("TestModel");
modelBuilder.Entity<TestModel>().HasPartitionKey(x => x.Pid);
modelBuilder.Entity<TestModel>().HasNoDiscriminator();
modelBuilder.Entity<TestModel>().HasKey(b => b.Id).HasName("id");
}
Using this, i still get an error.
InvalidOperationException: Unable to track an entity of type 'TestModel' because primary key property 'Id' is null.
I have also in trial and error, attempted to use. - HasName + HasKey / HasIndex - HasColumnName + Property