NServiceBus:如何扩展小数列的比例?
我们使用六位小数的十进制数,即 1.123456。现在,当我们使用 NServiceBus 并且需要将这个值保留在我们的传奇数据中时,我们遇到了麻烦。
当我们返回到传奇并再次获取我们的值时,该值是 1.12345。我还没有发现有人遇到同样的问题,但我想这不可能是一个独特的案例。
我的传奇数据看起来有点像,
public class MySagaData : IContainSagaData
{
public virtual Guid Id { get; set; }
public virtual string Originator { get; set; }
public virtual string OriginalMessageId { get; set; }
public virtual int Property1 { get; set; }
public virtual decimal Property2 { get; set; }
}
情况是,当 Property2 为 1.123456 并且它保留在我的传奇中时,返回到传奇并拾取它,则 Property2 为 1.12345。
我知道为什么会发生这种情况,NHibernate 创建了一个数据库字段 DECIMAL(19, 5)
,但我不知道如何解决我的问题。我不想自己创建表,而是让 NServiceBus 帮我创建。
有人吗?
We are using decimal numbers with a scale of six decimals, ie 1.123456. Now as we are using NServiceBus and we need to persist this value in our saga data we got trouble.
When we are returning to the saga and picks up our value again, the value is 1.12345. I haven't found anyone having the same problem but I guess this can't be a unique case.
My saga data looks kind of,
public class MySagaData : IContainSagaData
{
public virtual Guid Id { get; set; }
public virtual string Originator { get; set; }
public virtual string OriginalMessageId { get; set; }
public virtual int Property1 { get; set; }
public virtual decimal Property2 { get; set; }
}
The case is that when Property2 is 1.123456 and it is persisted in my saga, returning to the saga and pick it up then Property2 is 1.12345.
I know why it is happening, NHibernate creates a database field, DECIMAL(19, 5)
, but I don't know how to resolve my problem. I don't want to create the table myself but let NServiceBus do it for me.
Anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为如果您想更改默认映射小数的方式,您必须为 NHibernate 创建自定义方言。例如,如果您使用 SQL 服务器,请查看 Nhibernate 源代码中的 MsSql2000Dialect.cs。您可以看到它定义了一个小数列,如下所示:
您可以在 java 中查看如何在此处执行此操作的示例。 C#中基本是一样的
http://shashivelur.com/blog/2008/08/ override-hibernate-sql-types-mapping/
创建自定义方言后,您只需在 NHibernate 配置中进行设置:
或
I think you'll have to create a custom dialect for NHibernate if you want to change the way decimals are mapped by default. For example if your using SQL server have a look at MsSql2000Dialect.cs in the Nhibernate source code. You can see it defines a decimal column like this:
You can see an example of how to do it here in java. It's basically the same in C#
http://shashivelur.com/blog/2008/08/override-hibernate-sql-types-mapping/
Once you've created your custom dialect you just need to set it up in your NHibernate config:
or