Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Cannot convert double to single

Im getting an error:

"The 'BomAmountTaxRate' property on 'EoiQuote' could not be set to a 'System.Double' value. You must set this property to a non-null value of type 'System.Single'. "

The db table schema is :

QuoteID                 uniqueidentifier    Unchecked
SubmissionDate          datetime    Unchecked
RfqID                   uniqueidentifier    Unchecked
SupplierID                  uniqueidentifier    Unchecked
SupplierRef nvarchar(50)    Checked
BomAmountExTax          decimal(18, 2)  Unchecked
BomAmountCurrencyID         int Unchecked
BomAmountTaxRate            float   Unchecked
BomTaxAmount            decimal(18, 0)  Unchecked
FreightAmountExTax          decimal(18, 0)  Unchecked
FreightAmountCurrencyID int Unchecked
FreightAmountTaxRate    float   Unchecked
FreightTaxAmount            decimal(18, 0)  Unchecked
FreeFormParticulars         text    Checked
AvailabilityOpeningDate datetime    Checked
AvailabilityClosingDate datetime    Checked
Status                  int Unchecked
TransactionID   uniqueidentifier    Checked
Quantity                    int Unchecked
LastModified    datetime    Unchecked
ReviewedDate    datetime    Checked
RevisionID                 tinyint  Checked

And the EoiQuote POCO as follows:

public class EoiQuote
    {
        public Guid QuoteID { get; set; }

        public DateTime SubmissionDate { get; set; }

        public Guid RfqID { get; set; }

        public Guid SupplierID { get; set; }

        public string SupplierRef { get; set; }

        public decimal BomAmountExTax { get; set; }

        public int BomAmountCurrencyID { get; set; }

        public float BomAmountTaxRate { get; set; }

        public decimal BomTaxAmount { get; set; }

        public decimal FreightAmountExTax { get; set; }

        public int FreightAmountCurrencyID { get; set; }

        public float FreightAmountTaxRate { get; set; }

        public decimal FreightTaxAmount { get; set; }

        public string FreeFormParticulars { get; set; }

        public DateTime AvailabilityOpeningDate { get; set; }

        public DateTime AvailabilityClosingDate { get; set; }

        public int Status { get; set; }

        public Guid TransactionID { get; set; }

        public int Quantity { get; set; }

        public DateTime LastModified { get; set; }


        public EoiQuote()
        {
        }

    }

So as per usual the EF error makes absolutely no sense whatsoever. float = float : right?

like image 324
rism Avatar asked Nov 24 '13 23:11

rism


1 Answers

A float in SQL is not the same as a float in .Net. If you look at table of SqlDbType Enumeration you will find that SQL float is equivalent to double type.

Float->Double. A floating point number within the range of -1.79E +308 through 1.79E +308.

from C# Reference:

In .Net, a float is an alias for the System.Single type.

-3.4 × 1038 to +3.4 × 1038

like image 151
Claies Avatar answered Nov 12 '22 00:11

Claies