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
select r);
lastdownloadcount = f.Count();
}
return lastdownloadcount;
}
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.
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. http://anjlab.com/en/projects/opensource/sqlprofiler
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.
Warm Regards.
If my post provides any insight, please mark it as answer.
Marked as answer by ricka6 on Mar 02, 2012 06:14 PM
CSharper11
Member
51 Points
36 Posts
DateTime and string
Mar 02, 2012 03:28 PM|LINK
Hi,
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
select r);
lastdownloadcount = f.Count();
}
return lastdownloadcount;
}
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.
Thanks
CodeHobo
All-Star
18669 Points
2648 Posts
Re: DateTime and string
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.
http://anjlab.com/en/projects/opensource/sqlprofiler
Blog | Twitter : @Hattan
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: DateTime and string
Mar 02, 2012 04:59 PM|LINK
My advice is to run this in debug mode and see the value of lpaymentdate.
prahladyeri
Member
224 Points
43 Posts
Re: DateTime and string
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.
If my post provides any insight, please mark it as answer.