2013-11-24 48 views
6

即時得到一個錯誤:EF無法轉換雙單

"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'. "

db表模式是:

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 

而且EoiQuote POCO如下:

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() 
     { 
     } 

    } 

因此,作爲通常情況下,EF錯誤絕對沒有任何意義。 float = float:對嗎?

回答

19

SQL中的浮點數與.Net中的浮點數不同。如果您查看SqlDbType枚舉表,您會發現SQL浮點等價於double類型。

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

C# Reference

在.NET中,浮子是用於System.Single類型的別名。

-3.4 × 1038 to +3.4 × 1038