事件采购和SQL Server多重关系表 [英] Event Sourcing and SQL Server multiple relational tables

查看:175
本文介绍了事件采购和SQL Server多重关系表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用SQL Server 2016的事件采购。我们有全部的客户产品应用程序,每个应用程序都标有 CustomerId ,并在事件存储中获得一个指导行项目。这是写入事件存储GUID的主要标识符。产品应用程序带有许多不同的关系(每个客户都有多个地址,帐户,多个采购订单)。写事件存储将以任何我们选择的方式映射到关系数据库表。在数据库中,我们试图通过代理键而不是自然键来连接连接。



替代键可以是Guid,还是我们可以使用Integers(也许是Identity)请记住,Write Event存储中唯一的主标识符是客户ID应用程序的一个Guid(带有大量我们想要建模的表列属性的大json blob),但是,在读取模型中任何时候都可以改变的子关系表,在Write事件存储中没有子Guid。

解决方案

是的,您可以在特定的读取模型实现中使用任何您需要的内容,但是您需要考虑到读取模型随时可以重建 。所以,当一个读取模型被重新构建时,它可能会使用其他代理ID,或者只是以这样一种方式实现它,即每次获得相同的ID引用 Autoincrement 功能)。

你为什么不尝试去规范你的数据?在事件采购是常见的,以避免使用连接,而不是在读取模型中更快。


We use event sourcing with SQL Server 2016. We have total Customer Product Application, each is labelled by CustomerId and gets a single Guide line item in the event store. This is the primary identifier for write event store guids. The Product Applications comes with many different relational things, (which do not have guids but natural keys) each customer has Multiple Addresses, Accounts, Multiple purchase orders. The write event store will be mapped to a relational database tables any way we choose. In databases, we try to relate join by surrogate keys, instead of natural keys.

Can the surrogate keys be Guids, or can we utilize Integers (maybe Identity) for quicker Joins?

Remember the only primary identifier in Write Event store is a Guid from Customer ID app (big json blob with bunch of table column attributes we want to model), but the child relationships tables which can change any time in the read model, do not have child Guid in the Write event store.

解决方案

Yes, you can use whatever you need in a particular read model implementation but you need to take into account that a read model should be rebuildable at any time. So, when a read model is re-builded it may use other surrogate IDs or you just implement it in such a way that every time it gets the same IDs (I'm referring to the Autoincrement feature).

P.S. why don't you try to denormalize your data? In event sourcing is common to avoid using join instead of making them faster in the read model.

这篇关于事件采购和SQL Server多重关系表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆