0

In My sql db is Date , when i am using entity linq where clause , i am facing issue like "The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported." this is my where clause

TeamWorks.work_plan_dt == DateTime.Now.Date
var t = uow.TeamWork.GetAll().Where(t => t.work_plan_dt.Date == DateTime.Today.Date);
public DateTime? work_plan_dt { get; set; }

I have used dbfunctions.truncatetime and EntityFunctions.truncatetime still I am facing the issue , i should not change the datatype in db side from date to datetime , please help me

Advance thanks

2 Answers2

0

You cannot call your c# methods inside your linq code since there is no translation for them. If you have a datetime value, just calculate the value that you need and then pass it to linq query.

Like this

var someDate = DateTime.Now.AddDay(1);
var list = Db.MyTable.Where(x=>x.Date>someDate).ToList();
Ashkan S
  • 10,464
  • 6
  • 51
  • 80
0

You can change this:

var t = uow.TeamWork.GetAll().Where(t => t.work_plan_dt.Date == DateTime.Today.Date);

To this:

var t = ((from x in uow.TeamWork.GetAll() select x).ToList().Where(
                             T => T.work_plan_dt.Date == DateTime.Today.Date).ToList()

Or this:

var t = uow.TeamWork.GetAll().ToList().Where(t => t.work_plan_dt.Date == DateTime.Today.Date);
Farzin Kanzi
  • 3,380
  • 2
  • 21
  • 23