Cannot add a vertex where the partition key property has value 'null'
SimpleEvan opened this issue · comments
Describe the bug
Not sure how to set the partition key when creating a Vertex, error: "Cannot add a vertex where the partition key property has value 'null'". Getting data works fine.
Expected behavior
To add a vertex in my cosmos db
Version information
prerelease 8.0.0-preview-0707
Minimal working example
setup
_g = g.ConfigureEnvironment(env => env
.UseModel(GraphModel
.FromBaseTypes<Vertex, Edge>(lookup => lookup
.IncludeAssembliesOfBaseTypes())
.ConfigureProperties(model => model
.ConfigureElement(conf => conf
.IgnoreOnUpdate(x => x.TenantId))))
.UseCosmosDb(builder => builder
.At(uri, databaseName, graphName)
.AuthenticateBy(authKey)
.ConfigureWebSocket(builder => builder)));
.ConfigureQueryLoggingOptions(o => o
.SetQueryLoggingVerbosity(QueryLoggingVerbosity.None)))));
public class Person: Vertex
{
public string TenantId { get; set; }
public int Age { get; set; }
}
public class Vertex : IVertex
{
public object Id { get; set; }
public string Label { get; set; }
public string TenantId { get; set; } = "TenantId";
}
var _marko = await _g
.AddV(new Person { TenantId = "tenID", Age = 29, })
.FirstAsync();
Vertices in CosmosDB must have a PartitionKey property.
Have a look how it's done in the samples, especially here and here.
I've seen the example but I can't figure it out.
my pk is /tenantId
Does this mean I have to change the Vertex class
` public string PartitionKey { get; set; } = "TenantId"; `
or
public string PartitionKey { get; set; } = "/tenantId";
or
public string TenantId { get; set; } = "PartitionKey";
or do I not inherit van Vertex
and just create
public string PartitionKey { get; set; } = "TenantId";
in my Person class
Do I still need to create a new object in AddV or can I just pass an existing object
????!???!???
You can pass in existing objects, it just needs a PartitionKey property with a value of your choice. It's just a property after all. Having the property on the base class of all vertices is a good choice.
See also https://docs.microsoft.com/en-us/azure/cosmos-db/partitioning-overview
EDIT: I see the issue. Yes, of course the property in C# must be accordingly named. In your case, "tenantId". Casing is probably significant as well.
Issue solved, its a casing issue.
Thank you very much for your time.