I have this code. Basically i need to change the date and tell user that today, the store will be open from 10 am to 10 pm. So the time here is fixed.
from:-
today_date = "2020-03-23T00:00:00"
start_hour_time = "1900-01-01T10:00:00"
end_hour_time = "1900-01-01T22:00:00"
change to :-
start_newdatetime = "2020-03-23T10:00:00"
end_newdatetime = "2020-03-23T22:00:00"
DateTime todaysdate = DateTime.Now.Date;
var find_date = bdb.tbl_store
.Join(bdb.tbl_hour, a => a.start_hour_id, b => b.hour_id, (a, b) => new { a, b })
.Join(bdb.tbl_hour, a => a.a.end_hour_id, b => b.hour_id, (a, b) => new { a, b })
.Where(x => x.a.a.store_id == store_id )
.Select(x => new {
x.a.a.store_id,
start_hour_time = x.a.b.hour_time,
end_hour_time = x.b.hour_time,
start_newdatetime = todaysdate.Date+ x.a.b.hour_time.GetValueOrDefault().TimeOfDay,
end_newdatetime = todaysdate.Date + x.b.hour_time.GetValueOrDefault().TimeOfDay
}) .ToList();
the problem now, it is error. Because i want it to be on the same var.
"Message": "An error has occurred.", "ExceptionMessage": "LINQ to Entities does not recognize the method 'System.DateTime
GetValueOrDefault()' method, and this method cannot be translated into a store expression.", "ExceptionType": "System.NotSupportedException",
but it will be okey if i create another var to return the new value.