EF无法将双精度转换为单精度 [英] EF Cannot convert double to single

查看:128
本文介绍了EF无法将双精度转换为单精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出现错误:


EoiQuote上的 BomAmountTaxRate属性无法设置为
System.Double值。您必须将此属性设置为类型为 System.Single的非空值

"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为

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

    }

因此,像往常一样,EF错误绝对毫无意义。 float = float:是吗?

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

推荐答案

SQL中的float与.Net中的float不同。如果查看SqlDbType枚举表,您会发现SQL浮点数等于双精度类型。

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。浮点数在-1.79E +308到1.79E +308范围内。

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

来自C#参考

在.net,浮点数是System.Single类型的别名。

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


-3.4×10 38 到+3.4×10 38

-3.4 × 1038 to +3.4 × 1038

这篇关于EF无法将双精度转换为单精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆