1

The query below:

IEnumerable<activity> activityList = PortalContext.activity.Where(item => 
item.schakeling_id == newActivity.schakeling_id && 
item.startdt.Date == DateTime.Now.Date);

I am getting this error:

"The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."

I have tried multiple different ways but can't get it working. Any help would be appreciated.

ocuenca
  • 38,548
  • 11
  • 89
  • 102
Kip ei
  • 479
  • 6
  • 20

1 Answers1

3

Create a date variable outside of your query:

var currentdate=DateTime.Now.Date;

var activityList = PortalContext.activity.Where(item => 
                   item.schakeling_id == newActivity.schakeling_id 
                   && item.startdt.Date == currentdate);
ocuenca
  • 38,548
  • 11
  • 89
  • 102
  • Really strange. I though and am alomst sure that is the solution also. Somehow it is not working with me. Going home now, take a look at it tomorrow – Kip ei Mar 02 '17 at 16:18
  • I executed that query in linqpad and it worked, but try later with `DbFunctions.TruncateTime(item.startdt)==currentDate` – ocuenca Mar 02 '17 at 16:29
  • This worked for me! Really strange. I am sure I used your first answer in earlier projects. Any idea why? – Kip ei Mar 03 '17 at 12:51
  • I really don't have idea, maybe is EF version. What I did to test it was to use Linqpad and it worked, if I find out the answer I will let you know;) – ocuenca Mar 03 '17 at 13:04
  • I marked your response as the answer to my question. I also edited it with you're remarks for other people. – Kip ei Mar 03 '17 at 13:23