双重有什么区别?和一个双,为什么我不能隐式转换它们?

Met*_*uru 1 c# linq-to-sql

Visual Studio对我大吼大叫,在数据库中它是一个浮点数,而在我的课堂上它是双倍的.为什么我不能分配它,为什么它认为它是'双重'??

以下三行

    Confirmation confirm = new Confirmation();

    confirm.order = theOrder;

    confirm.totalPrice = theOrder.BillingAmount;
Run Code Online (Sandbox Code Playgroud)

这是确认DEF

    public class Confirmation
    {
        public Order order;

        public List<OrderItem> allProducts;

        public double totalPrice;
    }
Run Code Online (Sandbox Code Playgroud)

这是从我认为从.dbml draggy-droppy生成的代码中的BillingAmount DEF ...

[Column(Storage="_BillingAmount", DbType="Float")]
        public System.Nullable<double> BillingAmount
        {
            get
            {
                return this._BillingAmount;
            }
            set
            {
                if ((this._BillingAmount != value))
                {
                    this.OnBillingAmountChanging(value);
                    this.SendPropertyChanging();
                    this._BillingAmount = value;
                    this.SendPropertyChanged("BillingAmount");
                    this.OnBillingAmountChanged();
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

Ric*_*ich 7

在db中,如果列可以为空,则以C#表示Nullable<double>.double,作为一个值类型,不能为null ...但在db术语中,这是完全合法的.这就是为什么.Net有这种Nullable<T>类型的原因.您可以通过执行以下任一操作将其值分配给double

double d = nullableDouble ?? 0;
double d = (nullableDouble.HasValue) ? nullableDouble.Value : 0;
Run Code Online (Sandbox Code Playgroud)

等等...