Code: Select all
public abstract class BaseClass
{
public Guid Id { get; set; }
public string PartitionKey { get; set; } = string.Empty;
}
public class DerivedClass1 : BaseClass
{
public string PropertyA { get; set; } = string.Empty;
}
public class DerivedClass2 : BaseClass
{
public int PropertyB { get; set; }
}
< /code>
modelliert in EF -Kern wie SO: < /p>
modelBuilder.Entity(entity =>
{
entity.HasKey(e => e.Id);
entity.HasPartitionKey(e => e.PartitionKey);
entity.HasDiscriminator()
.HasValue("DerivedClass1")
.HasValue("DerivedClass2")
.IsComplete(true);
});
< /code>
und eine Repository -Methode, um eine einzelne Entität nach ID zu erhalten: < /p>
public async Task GetByIdAsync(Guid id, string partitionKey)
{
var db = new PlatformDbContext(new DbContextOptions
());
return await dbContext.BaseClasses
.SingleAsync(c => c.PartitionKey == partitionKey && c.Id == id);
}
< /code>
Da ich einen ID- und Partitionschlüssel zur Verfügung stelle, würde ich erwarten, dass dies ein Punkt ist. Die EF -Kernprotokolle zeigen jedoch, dass eine Abfrage durchgeführt wird. Die Zugabe von $ type
Code: Select all
Executed ReadNext (134.5222 ms, 3.03 RU) ActivityId='94f49da8-7517-43d7-9d1e-36b6e16798ec', Container='containerName', Partition='?', Parameters=[@__id_0=?]
SELECT VALUE c
FROM root c
WHERE ((c["$type"] IN ("DerivedClass1", "DerivedClass1") AND (c["Id"] = @__id_0))
OFFSET 0 LIMIT 2