Unable to cast object of type 'System.Double' to type 'System.Nullable`1[System.Single]'

≡放荡痞女 提交于 2019-12-11 06:13:38

问题


Why I'm getting the above error in this LINQ query - and how I can resolve it?

System.Nullable<float> totalFreight =
    (from cust in db.Customers
       join ord in db.Orders on cust.ordID equals ord.OrdID
      select ord.Freight).Sum();

Note: Freight attribute/column in Orders entity/table is of type float?. I'm using EF Core 1.1 with VS2015.

UPDATE: I'm trying to follow this and this MSDN examples.

UPDATE 2: I isolated the issue as follows. Moreover, I verified, by hovering the mouse over ord.Freight that Freight indeed is of type float:

var totalFreight =
        from cust in db.Customers
           join ord in db.Orders on cust.ordID equals ord.OrdID
          select ord.Freight

var testSum = totalFreight.Sum();

But still get the exact same error, this time at line: var testSum = totalFreight.Sum();

来源:https://stackoverflow.com/questions/43684621/unable-to-cast-object-of-type-system-double-to-type-system-nullable1system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!