Question

I've got a slight issue. I have a field where my customer wishes to store up to 4 decimal places back for a price (weird to say the least but still). So far, I'm only able to commit 2 decimal places back to the DB.

I am using Code First with Entity to do the saving and SQL Server 2008 R2 for my DB. Here is what I have fore each.

PurchaseOrder.cs (Code First)

public virtual decimal ShippingCost { get; set; }

PurchaseOrderService.cs (Service layer to save to Entity)

public virtual void UpdatePurchaseOrder(PurchaseOrder purchaseOrder)
{
    if (purchaseOrder == null)
       throw new ArgumentNullException("purchase order");

    _purchaseOrderRepository.Update(purchaseOrder);
}

PurchaseOrder table:

ShippingCost decimal(18, 4) NOT NULL

Ex. Shipping Cost is input as 10.5555 on the UI. All the way down throught the Service layer, it holds onto that value. Once it hits where it is sending it to Entity to save, the DB does not keep those extra values beyond 10.55.

Was it helpful?

Solution

Theree is an Entity Framework default value that uses only 2 decimals.

Decimal precision and scale in EF Code First

shows how to change that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top