Код: Выделить всё
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>
Моделируется в EF Core, как SO: < /p>
modelBuilder.Entity(entity =>
{
entity.HasKey(e => e.Id);
entity.HasPartitionKey(e => e.PartitionKey);
entity.HasDiscriminator()
.HasValue("DerivedClass1")
.HasValue("DerivedClass2")
.IsComplete(true);
});
< /code>
и метод репозитория, чтобы получить одну сущность по id: < /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>
Поскольку я предоставляю идентификатор и ключ раздела, я ожидаю, что это будет чтение. Но журналы EF Core показывают, что запрос выполняется. Добавление $ type Код: Выделить всё
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
Подробнее здесь: https://stackoverflow.com/questions/797 ... nt-reads-w
Мобильная версия