【发布时间】:2017-12-25 22:43:03
【问题描述】:
在 LINQ 中有没有将两个字段相乘的选项
public class details
{
public int qty { get; set; }
public decimal unitprice{ get; set; }
public decimal total{ get; set; }
}
select new details
{
qty =x.qty ,
unitprice= x.unitprice,
total= x.qty*x.unitprice,
}
如果不是,请给出任何正确的代码
【问题讨论】:
-
你只做对了。有什么问题?
-
在乘法之前检查 null 或 0 值。比如 total = (x.qty != 0 ? x.qty : 1) *(x.unitprice != 0 ? x.unitprice : 1)
标签: asp.net-mvc entity-framework linq linq-to-entities