'ASP.NET Core : how to sum the column based on another tables's column
I am new to ASP.NET Core.
public List<LineItem> LineItems { get; set; }
public double Total => this.LineItems.Sum(x => x.LineTotal);
LineItem
public int Quantity { get; set; }
public double UnitPrice { get; set; }
public double LineTotal => Math.Round(this.Quantity * this.UnitPrice, 2);
The error said Sum() is not used properly.
ArgumentNullException: Value cannot be null. (Parameter 'source')
Solution 1:[1]
I think this error may be due to Object reference not set to an instance of an object,you could try to modify the code:
public List<LineItem> LineItems { get; set; }
to
public List<LineItem> LineItems =new List<LineItem>???
And I get the excepted result after I changed the codes,If you have any other problems please tell me more details.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ruikai Feng |
