Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to pass the following query string "api/test?cvr=cvr&cvr=trd", but i keep getting an empty array of data.

if I search api/test?cvr=cvr, i get 10 results and if search api/test?cvr=trd, i get 1 result and when I search them together i get no data.

C#
public IEnumerable<database_data> GetType(string cvr)
       {
           DateTime yesterday = DateTime.Today.AddBusinessDays(-1);

           var data = from c in db.database_data
                      where c.UploadDate == yesterday
                      where (c.Cover == cvr ||
                       c.Cover == cvr)
                      select c;
           return data.ToList();
       }


I cannot seem to get this functionality to work. Any help would be very much appreciated.
Thank you
Posted
Updated 20-Jan-14 4:30am
v2

Have a look at this sample[^], taken from the MSDN page 101 LINQ Samples[^]

Edit: Are you sure that there are data entries from yesterday in your DB?
 
Share this answer
 
v2
Editing according to the Question Edit.

You Can try debugging the linq query by different ways to check if it returns rows.

One easy way is to debug by splitting the query to check

SQL
var data = from c in db.database_data
                       where c.UploadDate == yesterday
                       select c;
data =data.where (c.Cover == cvr || c.Cover == cvr)// for debugging purpose combine it to one once checking


Check whether the conditions are satisfied. Before that check that records are returned before applying filters.
 
Share this answer
 
v3
Well, to combine clauses in a where statement, all you need to do is:
C#
var data = from c in db.database_data
                       where c.UploadDate == yesterday &&
                        c.Cover == cvr
                       select c;
However, you might find that you get an issue with testing against UploadDate. The value you are storing in yesterday includes the time portion, so if UploadDate is actually a date, use
C#
c.UploadDate.Date == yesterday.Date
in your test.
 
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