Hi AbdulHaque,.
LINQ to Entities cannot translate most .NET Date methods (including the casting you used) into SQL since there is no equivalent SQL.
What you need to do is to change like below.
public ActionResult searchflight(string byflightDate, string byflightNo)
{
if (byflightDate != null && byflightNo != null && byflightNo != string.Empty && byflightDate != string.Empty)
{
DateTime _byflightDate = Convert.ToDateTime(byflightDate);
return View(db.tbl_FlightDetails.ToList().Where(x => Convert.ToDateTime(x.flightDate) == _byflightDate && x.flightNumber == byflightNo));
}
else if (byflightDate != null && byflightNo == string.Empty)
{
DateTime _byflightDate = Convert.ToDateTime(byflightDate);
return View(db.tbl_FlightDetails.ToList().Where(x => Convert.ToDateTime(x.flightDate) == _byflightDate));
}
else if (byflightDate == null && byflightDate == string.Empty && byflightNo != null && byflightNo != string.Empty)
{
return View(db.tbl_FlightDetails.ToList().Where(x => x.flightNumber == byflightNo || byflightNo == null));
}
else
{
return View(db.tbl_FlightDetails.ToList().Where(x => x.flightNumber == byflightNo || byflightNo == null));
}
}