首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

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

2013-10-23 
关于linq中写入算术表达式的问题using (TYLAS5Entities t new TYLAS5Entities()){var res from b in t

关于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();
            }

热点排行