简体   繁体   English

如何为NServicebus的NHibernate Saga Persister使用Version属性?

[英]How do I use a Version property for NServicebus's NHibernate Saga Persister?

Forgive me for asking a question that might have a totally obvious answer (RTFM), but how does one go about making the "Version property" mentioned here actually work? 请原谅我提出一个可能有明显答案的问题(RTFM),但是如何让这里提到的“版本属性”真正起作用? The provided links to Ayende's site here and the github repo here hint that this is possible. 所提供的链接Ayende的网站在这里和GitHub的回购这里暗示,这是可能的。 There is also this other SO link here that describes the same issue but does not really have a clear solution posted. 此处还有其他SO链接描述了相同的问题,但并未真正发布明确的解决方案。 I was also unable to find NSB sample code or anything in release notes or documentation related to this feature. 我也无法在与此功能相关的发行说明或文档中找到NSB示例代码或任何内容。 However, it's critical knowledge for anyone running sagas with multiple worker threads and ReadCommited. 但是,对于任何运行具有多个工作线程和ReadCommited的传奇的人来说,这都是关键知识。

Is it really as simple as adding an integer property called Version to your saga data class and a timestamp/rowversion to your saga data table? 是否真的像为saga数据类添加名为Version的整数属性以及为saga数据表添加时间戳/ rowversion一样简单? Is this really in the samples somewhere and I'm just not looking in the right place? 这是真的在某个地方的样本,我只是没有找对地方?

Also, based on the comments I've seen posted, it looks like there is a bug in NSB 3.x that involves this feature. 此外,根据我发布的评论,看起来NSB 3.x中存在涉及此功能的错误。 Will I need to upgrade to 4.x to get this feature or is there an easy way to get it working in 3.x? 我是否需要升级到4.x才能获得此功能,还是有一种简单的方法可以让它在3.x中运行?

Thanks! 谢谢!

EDIT: 编辑:

Using John Simon's answer below, I ran into an bug initially using the following NSB versions: 使用下面的John Simon的答案,我最初使用以下NSB版本遇到了一个错误:

NHibernate: 3.3.3.4001
NServiceBus: 4.3.1
NServiceBus.Host: 4.3.1
NServiceBus.Interfaces: 4.3.3
NServiceBus.NHibernate: 4.3.0
NServiceBus.StructureMap: 4.3.1

I opened this issue on github and after some back & forth, tried a dev build containing a fix and got this to work. 在github上打开了这个问题 ,经过一些来回,尝试了一个包含修复程序的开发构建并让它工作。 The official fix was released in NServiceBus.NHibernate v4.4.0. 官方修复程序在NServiceBus.NHibernate v4.4.0中发布。

My variation on the answer was to use this with a timestamp SQL column: 我对答案的变化是将它与时间戳SQL列一起使用:

[RowVersion]
public virtual byte[] Version { get; set; }

After spending a couple days hammering on it, it looks good. 经过几天的锤击,看起来不错。

In v3 all you should need to do is define a version property on the saga: 在v3中你需要做的就是在saga上定义一个version属性:

public virtual int Version {get;set;}

In v4 we default to "optimistic-all" concurrency model and if you need custom row level concurrency you do the same as v3 + an attribute: 在v4中,我们默认使用“optimistic-all”并发模型,如果需要自定义行级并发,则执行与v3 +属性相同的操作:

[RowVersion]
public virtual int Version { get; set; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM