Я использую следующие модели:
Код: Выделить всё
public class DocumentReadModelEntity where T : IDocumentReadModel
{
public Guid Id { get; set; }
public T Data { get; set; }
public DocumentReadModelEntity()
{
}
public DocumentReadModelEntity(T data)
{
Data = data;
Id = data.Id;
}
}
Код: Выделить всё
public sealed class SupplierReadModel : IDocumentReadModel
{
public string? Description { get; set; }
public string? Website { get; set; }
public Guid? LogoFileId { get; set; }
public bool IsActive { get; set; }
public bool ShouldSendRemittanceEmail { get; set; }
public List Blocks { get; set; }
public List Estates { get; set; }
public Guid CompanyId { get; set; }
public CompanyShortData? CompanyData { get; set; }
public BankAccountModel? BankAccount { get; set; }
}
Код: Выделить всё
[Owned]
public abstract class ReadModelDataModel
{
}
Код: Выделить всё
public class SupplierBlockModel : ReadModelDataModel
{
public Guid BlockId { get; set; }
public BlockShortData? BlockData { get; set; }
}
Код: Выделить всё
public class BlockShortData : ReadModelDataModel
{
public string CustomId { get; set; }
public string BlockName { get; set; }
[JsonIgnore]
public string FullName => $"[{CustomId}] {BlockName}";
}
Код: Выделить всё
public static void ApplyDefaultConfiguration(this EntityTypeBuilder builder) where T : class, IDocumentReadModel
{
builder.ToTable(typeof(T).Name);
builder.HasKey(x => x.Id);
builder.OwnsOne(x => x.Data, x =>
{
x.ToJson();
});
}
Код: Выделить всё
return await _entities.AsNoTracking()
.Where(x => ids.Contains(x.Id))
.Select(x => x.Data)
.ToListAsync();
Код: Выделить всё
_entities = _dbContext.Set();
Код: Выделить всё
public class DocumentStore : IDocumentStore where T : class, IDocumentReadModel, new()
Код: Выделить всё
public void Update(T updated)
{
var entity = new DocumentReadModelEntity(updated);
_entities.Entry(entity).State = EntityState.Modified;
}
Код: Выделить всё
public async Task Save()
{
await _dbContext!.SaveChangesAsync();
}
Код: Выделить всё
DocumentReadModelEntity {Id: 018d834f-75d9-48eb-8af1-543579976bc5} Modified
Id: '018d834f-75d9-48eb-8af1-543579976bc5' PK
Data:
Подробнее здесь: https://stackoverflow.com/questions/779 ... d-postgres
Мобильная версия