Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 02, 2012 05:05 PM by prahladyeri
Mar 02, 2012 03:28 PM|LINK
I have a function like
public object ContributorLastDownloadCount( int cid, string lastpaymentdate)
var lpaymentdate = Convert.ToDateTime(lastpaymentdate);
var f = (from d in db.dyFileDownloads
join r in db.vwResourceFiles on d.FileId equals r.Id
join fd in db.dyFileDownloads_Details on d.Id equals fd.Id
where r.ContributorId == cid && fd.DownloadDate == lpaymentdate
lastdownloadcount = f.Count();
I am sure the contributorid and Downloaddate are passed and I get a return value of 0 instead of the count. I am guessing the problem is on the string to datetime conversion. Can anyone advise please.
Mar 02, 2012 03:54 PM|LINK
Check to make sure that your joins are set up correctly, by default I believe a LINQ join is an INNER JOIN. Make sure there are entries in vwResourceFiles and dyFileDownloads_Details with the corresponding id's
Finally, download this sql profiler and point it at your sql server. Then run your mvc application, you should now be able to see what the sql query that is resulting from the LINQ statement above.
Mar 02, 2012 04:59 PM|LINK
My advice is to run this in debug mode and see the value of lpaymentdate.
Mar 02, 2012 05:05 PM|LINK
My guess is that either one of your variables - fd.DownloadDate and lpaymentdate consist of time portions and not just date, and hence they are not matched inside your LINQ query. As Dan suggests, you have to debug and check if this is the case.