Click here to Skip to main content
15,868,236 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Dear all,

I am trying to call a query, which can display data by distinct names only and based on other conditions as well:

C#
DateTime? yesterday = DateTime.Today.AddBusinessDays(-4);

                var data = from c in db.data_qy
                           where c.UploadDate == yesterday &&
                            c.Cover == "storm"
                            .OrderByDescending(a => a.UploadDate)
                            .Distinct()
                           select (c.Name);

                if (!data.Any())
                {
                    var message = string.Format("No data found");
                    return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
                }

                return Request.CreateResponse(HttpStatusCode.OK, new {data });
            }


I am currently getting a -- 'char' does not contain a definition for 'UploadDate' and no extension method 'UploadDate' accepting a first argument of type 'char' could be found (are you missing a using directive or an assembly reference?) -- error on the 'UploadDate' where clause.
Please advice, in what I may be missing from the code above.

Thanks in advance.
Posted
Comments
Herman<T>.Instance 6-May-14 7:38am    
change == to equals
miss786 6-May-14 7:48am    
thank you for your response back. I tried that but it throws many compiling errors, in regards to 'a' not existing and many more. Please advice further, if possible. Thanks

try this...


C#
var data = (from c in db.data_qy
            where c.UploadDate == yesterday &&
                  c.Cover == "storm"

             select (c.Name)).OrderByDescending(a => a.UploadDate).Distinct();
 
Share this answer
 
v2
Comments
miss786 6-May-14 8:22am    
Thank you very much for your response and help. I am sorry to inform, I have tried your code, but it outputs following compiling error:

'string' does not contain a definition for 'UploadDate' and no extension method 'UploadDate' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Thanks.
MNamrata 6-May-14 8:27am    
Check datatype of UploadDate and update edmx from database.
Make sure it is updated.
miss786 6-May-14 9:03am    
The datatype for 'UploadDate' is nullable datetime and the data entity is created through entity framework. I am still getting the above error on the uploadDate fieldname. This is what my current code looks like:

public HttpResponseMessage Get(DateTime? date)
{
if (User.IsInRole("admin"))
{

DateTime yesterday = DateTime.Today.AddBusinessDays(-4);


var data = (from c in db.data_qy
where c.UploadDate == yesterday &&
c.Cover == "storm"
select (c.Name)).OrderByDescending(a => a.UploadDate).Distinct();

if (!data.Any())
{
var message = string.Format("No data found");
return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);

}

return Request.CreateResponse(HttpStatusCode.OK, new {data });

}

return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Access Denied, Please try again.");
}
MNamrata 6-May-14 9:37am    
Remove nullable and give default value as current datetime. Check mapping in entity. In db uploadedDate column not found. May be colums mismatched with database. Otherwise code does not have any issue.
hey u must be from pakistan ??? right :D
 
Share this answer
 
Comments
Sanket Saxena 6-May-14 8:19am    
Is this your solution buddy???

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