linq平均查询中的错误 [英] error in linq average query

查看:62
本文介绍了linq平均查询中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hello i have a linq query and i am going to findout average of rating in this query but its giving me error below is my query







fv1.DataSource = from st in obj.Book_details
                                
                               join f in obj.Rating_tables on st.Book_Id equals f.Book_id
                                 where st.Book_Id == book_id
                                 select new {  st.Book_Id, st.Book_index, st.Category, st.Edition,                 st.Authoers_Id ,f.Rating.Average()};
                fv1.DataBind();
















table book_detail--
book_id   book_namne    price
  1          ok          45
  2          pkl         56




now another table is 




rating_table
rating_id  book_id  rating
  1           1        4
  2           1        3
  3           2         5
   4          2        1
   5           1        3




now i want to find avg rating
where my linq query is 




var fgh  =  from st in obj.book_detail
            join t in obj.rating_table st.book_id equals t.book_id
            where st.book_id == bookid
            select new {st.book_name , st.book_id , st.price ,}




i am new in asp.net please help me in finding average rating

推荐答案

要使聚合工作,您需要执行 GROUP BY 平均需要谓词,请阅读以下内容: http://stackoverflow.com/questions/5313665/c-sharp-linq -average [ ^ ]
For aggregates to work you need to do a GROUP BY and Average takes a predicate, read the following : http://stackoverflow.com/questions/5313665/c-sharp-linq-average[^]


请参阅链接 http://stackoverflow.com/questions/1421427/join-and-calculate-average-of-column-using-linq-to-sql [ ^ ]

处理相同的
Refer the link http://stackoverflow.com/questions/1421427/join-and-calculate-average-of-column-using-linq-to-sql[^]
which deals with the same


这篇关于linq平均查询中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆