开发者

NServiceBus: How do I extend scale for a decimal column?

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 t开发者_开发百科o create the table myself but let NServiceBus do it for me.

Anyone?


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:

RegisterColumnType(DbType.Decimal, "DECIMAL(19,5)");

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:

nhCibfig.SetProperty(Environment.Dialect, typeof(MyCustomDecimalDialect).AssemblyQualifiedName)

or

<property name="dialect">MyAssembly.MyCustomDecimalDialect, MyAssembly</property>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜