日期:2014-05-20  浏览次数:20764 次

关于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),