If given a table structure using TPH in Entity Framework.
class ContactLink {
Guid Contact_Link_ID { get; set;} //pk
Guid Tenant_ID { get; set;} //fk
Guid Contact_ID { get; set;} //fk
}
class ContactLinkCustomer : ContactLink {
Guid Contact_Link_ID { get; set;} //fk
Guid Customer_ID { get; set;} //fk
}
How should I configure the elastic scale schema info for split merge operations since Entity framework does not include the base class properties in the derived class's table? Specifically Tenant_ID, which is my point map shard key.
SchemaInfo schemaInfo = new SchemaInfo();
schemaInfo.Add(new ShardedTableInfo("dbo", "ContactLinkCustomer", ???));
smm.GetSchemaInfoCollection().Add("ShardName", schemaInfo);
Update: ContactLink is not abstract.
Update 2: I should note that ContactLink is also in my DbContext and is queried independently from ContactLinkCustomer.
Update 3: I am not using TPH, we are actually using TPT. Which is what caused multiple tables instead of the single table with a discriminator.
The below works for me, with the caveat that there is no database-level constraint that keeps the Tenant_ID in sync so they can get out of sync if any code modifies these tables directly through T-SQL (not through EF).
Additional classes that I used for testing are below.
Console output:
There also might be some kind of mapping-based solution possible. I tried the below but it doesn't work. Perhaps with some more experimentation it could work, but the above solution seems good enough for me so I didn't explore it further.