读书人

关于linq中写入算术表达式的有关问题

发布时间: 2013-10-23 11:39:13 作者: rapoo

关于linq中写入算术表达式的问题


using (TYLAS5Entities t = new TYLAS5Entities())
{
var res = from b in t.T_BookStorage
where b.BookGUID == guid
join c in t.T_CollectDept
on b.CollectDeptCode equals c.CollectDeptCode
select new
{
BarCode=b.BarCode,
CollectDeptName =c.CollectDeptName,
ReceiveDate=b.ReceiveDate,
Price=b.Price,
折后价=b.PriceRate*Convert.ToDouble(b.Price), //这里搞不定
State=b.State
};
return res.ToList().ToDataTable();
}

如上,我需要得到一个原价乘以折扣后的折扣价,但是这样始终有错,想想挺合理呀,求大侠帮忙!!! linq
[解决办法]
Convert.ToDouble可能不能在数据端执行。

先AsEnumerable再执行。
[解决办法]
最后少了个)啊,IDE 已经提示了啊:

using (TYLAS5Entities t = new TYLAS5Entities())
{
var res = (from b in t.T_BookStorage
where b.BookGUID == guid
join c in t.T_CollectDept
on b.CollectDeptCode equals c.CollectDeptCode
select new {b,c}).AsEnumerable().Select(x=>
{
BarCode=x.b.BarCode,
CollectDeptName =x.c.CollectDeptName,
ReceiveDate=x.b.ReceiveDate,
Price=x.b.Price,
折后价=x.b.PriceRate*Convert.ToDouble(x.b.Price),


State=x.b.State
});
return res.ToList().ToDataTable();
}

读书人网 >.NET

热点推荐