Click here to Skip to main content
15,878,048 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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()};

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

now another table is 

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 please help me in finding average rating
Updated 17-Nov-13 21:12pm
Er Daljeet Singh 18-Nov-13 0:22am    
What error you are getting.
Omprakash Kukana 18-Nov-13 0:25am    
Error 667 Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.
Omprakash Kukana 18-Nov-13 0:26am    
problem is here basically
Er Daljeet Singh 18-Nov-13 0:40am    
I don't think you will get Average() function with f.Rating beacuse it a returning a single value and you will not get average function there.

For aggregates to work you need to do a GROUP BY and Average takes a predicate, read the following :[^]
Share this answer
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900