gpt4 book ai didi

c# - 读数据库上的字段没有出现在写数据库中是否正常?

转载 作者:行者123 更新时间:2023-11-30 21:30:11 26 4
gpt4 key购买 nike

CQRS 写入数据库包含与 CQRS 读取数据库不同的字段是否正常?例如,在上面的情况下,Product.Description 在读取端(NoSQL)持久化但在写入端(SQL Server)不持久化是否正常?

我意识到写入端选择的数据库 (RDBMS) 的数据结构可能与读取端选择的数据库 (NoSQL) 不同。我特别询问是否“允许”选择在读取端和写入端保留哪些数据字段。

我问的原因是我正在阅读的一本书暗示这是正常的,但是,我在书中或网上找不到任何支持这一点的例子。

请看下面的代码:

public class Product
{
public Guid Id { get; set; }
public string Code { get; set; }
public string Description { get; set; }

public void LookupDescriptionByCode(List<ProductDescriptionLookup> productCodes)
{
Description = productCodes.Find(x => x.Code == Code).Description;
}
}

最佳答案

Is it normal for the CQRS write database to contain different fields to the CQRS Read database?

通常,写数据库将是一个超集(大于)读数据库。

is it normal for Product.Description to be persisted on the read side (NoSQL) but not on the write side (SQL Server)?

不,但也许。

如果您想象一个具有单一写入数据库的系统,那么“记录簿”就是写入数据库,所有内容都将存在于其中;读取数据库只是写入数据库中信息的缓存副本。

但是,如果您要分解这个整体,读取模型可能会结合来自多个写入模型的信息。因此写入模型可能只知道产品代码,但读取模型可能有产品描述(因为它使用代码从“其他地方”查找描述)。

但是在系统中的某处,您在任何给定时间都有“该”产品代码的官方副本。

I have an event log, which is the book of record. I am confused why a write database is needed as well. I can see the benefit of persisting certain domain objects to the write database, however not all of them?

如果您正在进行事件溯源,那么您的事件日志通常存储在您的写入数据库中(可能是 RDBMS,也可能是专用的消息存储)。

Is it fair to say that if there is an EventStore/EventLog/IntegrationLog then a write database (relational tables for each domain object) is not needed.

我认为,如果您的事件存储充当记录簿,那么您不需要关系表来充当这些相同实体的记录簿,这还远远不够。

例如,您可以对部分领域而不是全部领域使用事件溯源。或者您可能希望缓存表示以提高写入效率。或者……

关于c# - 读数据库上的字段没有出现在写数据库中是否正常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54639487/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com