I've looked for similar answers to this issue but none of them seem to fix this issue for me.
I'm getting a PartitionKey extracted from document doesn't match the one specified in the header
when attempting to run the code below against the cosmosDb emulator...
CosmosClient cosmosClient = new CosmosClient("AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", new CosmosClientOptions()
{
SerializerOptions = new CosmosSerializationOptions()
{
PropertyNamingPolicy = CosmosPropertyNamingPolicy.CamelCase
}
});
var database = await cosmosClient.CreateDatabaseIfNotExistsAsync("EventCatalogDb");
var newContainer = await database.Database.CreateContainerIfNotExistsAsync("Events", "/CategoryId");
var CategoryConcert = new Category
{
Id = Guid.Parse("b0788d2f-8003-43c1-92a4-edc76a7c5dde"),
Name = "Concerts"
};
var myEvent = new Event
{
Id = Guid.Parse("b419a7ca-3321-4f38-be8e-4d7b6a529319"),
Name = "Clash of the DJs",
Price = 85,
Artist = "DJ 'The Mike'",
Date = new DateTime(1466424490000),
Description = "DJs from all over the world will compete in this epic battle for eternal fame.",
ImageUrl = "https://gillcleerenpluralsight.blob.core.windows.net/files/GloboTicket/dj.jpg",
CategoryId = CategoryConcert.Id.ToString(),
CategoryName = CategoryConcert.Name
};
var eventResponse = await newContainer.Container.CreateItemAsync(myEvent, new PartitionKey(myEvent.CategoryId));
I can't see what is wrong. My partition key path looks correct as does the value for the partition key.
Edit
Event class
public class Event : IEntity
{
public Guid Id { get; set; }
public string Name { get; set; }
public string CategoryId { get; set; }
public string CategoryName { get; set; }
public int Price { get; set; }
public string Artist { get; set; }
public DateTime Date { get; set; }
public string Description { get; set; }
public string ImageUrl { get; set; }
}
Event
class? – Arca ArtemCreateContainerIfNotExistsAsync("Events", "/CategoryId");
toCreateContainerIfNotExistsAsync("Events", "/categoryId");
to see if that'll help – Arca Artem