मुझे पता है कि यह क्यों हो रहा है लेकिन क्या कोई मुझे वाक्यविन्यास की सही दिशा में इंगित कर सकता है?LINQ.SUM() और nullable डीबी मान
वर्तमान में मेरे पास है:
var expense = from e in db.I_ITEM
where e.ExpenseId == expenseId
select e;
return expense.Sum(x => x.Mileage ?? 0);
मेरे समस्या यह है कि x.Mileage प्रकार की है कि "डबल?" और डीबी में शून्य मान है।
त्रुटि मैं मिलता है:
Exception Details: System.InvalidOperationException: The cast to value type 'Double' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.
क्या सही सिंटैक्स होगा?
यह वास्तव में एक है जो कुछ भी करने के लिए Linq में बग नहीं है? टाइप सुरक्षा टूट गई है। – sinelaw
@sinelaw: ऐसा लगता है, हाँ। यद्यपि अधिक जानकारी के बिना कहना मुश्किल है। –