entity framework - How to do a simple Count in Linq? -
i wanted paging style table, neerdinner example fetches entire data pagginglist
type, , have more 10 000 rows fetched, skipped part.
so come query
var r = (from p in db.prizes join c in db.calendars on p.calendar_id equals c.calendar_id join ch in db.challenges on c.calendar_id equals ch.calendar_id join ca in db.challengeanswers on ch.challenge_id equals ca.challenge_id join cr in db.challengeresponses on ca.challenge_answer_id equals cr.challenge_answer_id p.prize_id.equals(prizeid) && ch.day >= p.from_day && ch.day <= p.to_day && ca.correct.equals(true) && ch.day.equals(day) orderby cr.subscribers.name select new possiblewinner() { name = cr.subscribers.name, email = cr.subscribers.email, subscriberid = cr.subscriber_id, challengeday = ch.day, question = ch.question, answer = ca.answer }) .skip(size * page) .take(size);
problem is, how can total number of results before take
part?
i thinking of:
var t = (from p in db.jk_prizes join c in db.jk_calendars on p.calendar_id equals c.calendar_id join ch in db.jk_challenges on c.calendar_id equals ch.calendar_id join ca in db.jk_challengeanswers on ch.challenge_id equals ca.challenge_id join cr in db.jk_challengeresponses on ca.challenge_answer_id equals cr.challenge_answer_id p.prize_id.equals(prizeid) && ch.day >= p.from_day && ch.day <= p.to_day && ca.correct.equals(true) && ch.day.equals(day) select cr.subscriber_id) .count();
but query on again...
anyone has suggestions on how can do effectively ?
if take query such:
var qry = (from x in y select x).count();
...linq sql clever enough make select count
query, potentially rather efficient (efficiency depend more on conditions in query). bottom line count operation happens in database, not in linq code.
Comments
Post a Comment