Peter de Bruijn
Peter de Bruijn

Reputation: 822

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?

Upvotes: 0

Views: 84

Answers (2)

Simon Mourier
Simon Mourier

Reputation: 139075

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).

Upvotes: 1

meziantou
meziantou

Reputation: 21347

You can set the desired precision for the decimal columns at producer level:

<cf:producer name="SQL Server" typeName="CodeFluent.Producers.SqlServer.SqlServerProducer, CodeFluent.Producers.SqlServer">
  <cf:configuration
                  decimalScale="2"
                  decimalPrecision="6" />
</cf:producer>

The generated column is

[Price] [decimal] (6,2) NOT NULL

Upvotes: 1

Related Questions