Search code examples
codefluent

Decimal precision codefluent


How can I set decimal precision to reduce database size? I have a decimal value in my codefluent model. The SQL producer produces a decimal (28,13) field for this property. However, I use the property to store values that will never have more than two digits after the decimal seperator and not more than four before. A 28,13 is overkill. How can I force the producer to make it a (6,2) decimal?


Solution

  • You can use SQL Server Producer specific size and dataType attributes, like this:

    <cf:property name="MyNumericProperty"
        typeName="decimal"
        cfps:size="6,2"
        cfps:dataType="numeric"
        xmlns:cfps="http://www.softfluent.com/codefluent/producers.sqlserver/2005/1"
    />
    

    Note that, most of the time, decimal is also overkill in .NET (16 bytes).