In fact I think you can use join statement to connect the two tables with the primary key and the foreign key between in the two tables,and then use Count to do the following things……
【Sample】
var result = from f in db.Feedbacks
join r in db.Ratings on f.FeedId equals r.FeedId into temp
select new
{
AttributeName = db.Feedbacks.Where(f=>f.FeedId==temp.Key).FirstOrDefault().Name,
Good = temp.Count(r=>r.……Your Good condition here),
Bad = temp.Count(r=>r.……Your Bad condition here)
};
Error 58 'System.Collections.Generic.IEnumerable<Rating.DAL.tblRating>' does not contain a definition for 'Key' and no extension method 'Key' accepting a first argument of type 'System.Collections.Generic.IEnumerable<Rating.DAL.tblRating>' could be
found (are you missing a using directive or an assembly reference?) E:\Developments\Rating\Rating\Admin\Default.aspx.cs 121 82 Rating
Error 58 'System.Collections.Generic.IEnumerable<Rating.DAL.tblRating>' does not contain a definition for 'Key' and no extension method 'Key' accepting a first argument of type 'System.Collections.Generic.IEnumerable<Rating.DAL.tblRating>' could be
found (are you missing a using directive or an assembly reference?) E:\Developments\Rating\Rating\Admin\Default.aspx.cs 121 82 Rating
Please make sure that your net framework's version is 3.5 or above,and you've referred System.Xml.LINQ
lasantha
Contributor
2361 Points
844 Posts
Linq query help
Apr 27, 2012 08:43 AM|LINK
Hi
This is my table stucture.
Feedback table
FeedId BranchId Name Description Tel Date
......... ......... ........ .............. ..... .......
Rating Table
RateId FeedId AttId RateValue
1 1 1 5
2 1 2 3
Rate Values are Bad=1 ....Good=4 simething like that.
I want to get attribute vise rating counts in any date range
ex
Attribute 1 Bad 3 Good 20
Attribute 2 Bad 15 Good 12
Thanks
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Linq query help
Apr 29, 2012 12:43 AM|LINK
Hello:)
In fact I think you can use join statement to connect the two tables with the primary key and the foreign key between in the two tables,and then use Count to do the following things……
【Sample】
var result = from f in db.Feedbacks
join r in db.Ratings on f.FeedId equals r.FeedId into temp
select new
{
AttributeName = db.Feedbacks.Where(f=>f.FeedId==temp.Key).FirstOrDefault().Name,
Good = temp.Count(r=>r.……Your Good condition here),
Bad = temp.Count(r=>r.……Your Bad condition here)
};
lasantha
Contributor
2361 Points
844 Posts
Re: Linq query help
Apr 30, 2012 07:47 AM|LINK
There is a small error.
Error 58 'System.Collections.Generic.IEnumerable<Rating.DAL.tblRating>' does not contain a definition for 'Key' and no extension method 'Key' accepting a first argument of type 'System.Collections.Generic.IEnumerable<Rating.DAL.tblRating>' could be found (are you missing a using directive or an assembly reference?) E:\Developments\Rating\Rating\Admin\Default.aspx.cs 121 82 Rating
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Linq query help
Apr 30, 2012 08:02 AM|LINK
Please make sure that your net framework's version is 3.5 or above,and you've referred System.Xml.LINQ
lasantha
Contributor
2361 Points
844 Posts
Re: Linq query help
Apr 30, 2012 09:00 AM|LINK
yah i use .net framework 4 and refered System.Xml.Linq also.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Linq query help
May 01, 2012 05:30 AM|LINK
Feeling curious……Are you using EF or DataTable?
amitpatel.it
Star
8070 Points
1880 Posts
Re: Linq query help
May 01, 2012 05:39 AM|LINK
Here is the good sample for this to get cound of group by value
http://stackoverflow.com/questions/695506/linq-left-join-group-by-and-count
MCPD Enterprise and Web Application
MCTS Web, Window and Enterprise Application
lasantha
Contributor
2361 Points
844 Posts
Re: Linq query help
May 03, 2012 05:15 AM|LINK
I coudnt find a way to retrieve all count for each attributes. So loop through the recordlist and use dynamic datatable.