问题
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