I need to construct linq, but day (date time type, i.AllowedTime.AllowedDate.Day), hours and minutes (int type) stores differently. I try to make it:
DateTime date = DateTime.Now.Date;
IQueryable<ITW2012Mobile.Core.DataTable.MeetingModel2> result = null;
if (status == MeetingStatus.RequestedOfYou)
{
result = from i in _dbContext.Meetings
where i.UserInvitedID == CurrentUserID && i.MeetingStatus == null && EntityFunctions.TruncateTime(i.AllowedTime.AllowedDate.Day) >= date
select new ITW2012Mobile.Core.DataTable.MeetingModel2()
{
Name = i.UserInviter.FirstName + " " + i.UserInviter.LastName,
Company = i.UserInviter.Company,
MeetingID = i.MeetingID,
Time = EntityFunctions.AddMinutes(EntityFunctions.AddHours(i.AllowedTime.AllowedDate.Day, i.AllowedTime.Hour).Value, i.AllowedTime.Minute).Value,
Image = i.UserInviter.ProfileImage,
Username = i.UserInviter.aspnet_User.UserName
};
}
but got an exception :
{“The datepart hour is not supported by date function dateadd for data
type date.”}
how to do it?
ADDED class MeetingModel2
public class MeetingModel2
{
public int MeetingID { get; set; }
public string Name { get; set; }
public string Company { get; set; }
public DateTime Time { get; set; }
public string Image { get; set; }
public string Username { get; set; }
}
The field “Time” in the database you’re querying is likely a Date data type. You cannot perform time operations like adding minutes or hours to a Date type. If you changed that field to be a DateTime you’d probably be okay.