nullable dateTime linq query issue
-
Hi all, I am trying to run a query which can allow to output 'UploadDate' value only. This is what I currently have and i keep getting a -- Cannot implicitly convert type 'System.DateTime?' to 'API_09.database_BD'-- error, on the following code:
public database_BD GetDate()
{
var data = db.database_BD.Select(d => d.UploadDate)
.OrderByDescending(c => c)
.FirstOrDefault();return data; // error line. }
Database_BD Entity framework class:
public partial class database_BD
{
public Nullable UploadDate { get; set; }
public string uUsername { get; set; }
}any suggestions and help would be most welcome.
-
Hi all, I am trying to run a query which can allow to output 'UploadDate' value only. This is what I currently have and i keep getting a -- Cannot implicitly convert type 'System.DateTime?' to 'API_09.database_BD'-- error, on the following code:
public database_BD GetDate()
{
var data = db.database_BD.Select(d => d.UploadDate)
.OrderByDescending(c => c)
.FirstOrDefault();return data; // error line. }
Database_BD Entity framework class:
public partial class database_BD
{
public Nullable UploadDate { get; set; }
public string uUsername { get; set; }
}any suggestions and help would be most welcome.
-
Hi all, I am trying to run a query which can allow to output 'UploadDate' value only. This is what I currently have and i keep getting a -- Cannot implicitly convert type 'System.DateTime?' to 'API_09.database_BD'-- error, on the following code:
public database_BD GetDate()
{
var data = db.database_BD.Select(d => d.UploadDate)
.OrderByDescending(c => c)
.FirstOrDefault();return data; // error line. }
Database_BD Entity framework class:
public partial class database_BD
{
public Nullable UploadDate { get; set; }
public string uUsername { get; set; }
}any suggestions and help would be most welcome.
If you only want to return the upload date, change the return type of your
GetDate
method toDateTime?
and everything should work:public DateTime? GetDate()
{
return db.database_BD.Select(d => d.UploadDate)
.OrderByDescending(c => c)
.FirstOrDefault();
}If the return type needs to be
database_BD
, then you'll need to return that type:public database_BD GetDate()
{
var data = db.database_BD.Select(d => d.UploadDate)
.OrderByDescending(c => c)
.FirstOrDefault();return new database\_BD { UploadDate = data };
}
If you want the full details of the latest record, then you'll need to change your query:
public database_BD GetDate()
{
return db.database_BD
.OrderByDescending(d => d.UploadDate)
.FirstOrDefault();
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
If you only want to return the upload date, change the return type of your
GetDate
method toDateTime?
and everything should work:public DateTime? GetDate()
{
return db.database_BD.Select(d => d.UploadDate)
.OrderByDescending(c => c)
.FirstOrDefault();
}If the return type needs to be
database_BD
, then you'll need to return that type:public database_BD GetDate()
{
var data = db.database_BD.Select(d => d.UploadDate)
.OrderByDescending(c => c)
.FirstOrDefault();return new database\_BD { UploadDate = data };
}
If you want the full details of the latest record, then you'll need to change your query:
public database_BD GetDate()
{
return db.database_BD
.OrderByDescending(d => d.UploadDate)
.FirstOrDefault();
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Dear Richard, Your first solution worked. I did not realize, i was missing something so silly. I appreciate your time and help. Many thanks.
No problem - we've all had days like that! :)
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer