The following throws an error:
public FieldViewer GetFieldViewByFieldIDIPAndUserByDate( int fieldID, string ip, string userID, DateTime date )
{
return this.
One way to fix this is to perform that part of the filtering outside of the LINQ to Entities provider, using the LINQ to Objects provider. To do that, append a call to AsEnumerable()
before that operation:
public FieldViewer GetFieldViewByFieldIDIPAndUserByDate( int fieldID, string ip, string userID, DateTime date )
{
return this.context.FieldViewers.Where( x =>
x.Field.FieldID == fieldID &&
x.Viewer.IPAddress == ip &&
x.Viewer.User.Id == userID)
.AsEnumerable()
.Where(x => date.Subtract( x.Viewer.CreatedAt ).TotalMinutes >= 10)
.FirstOrDefault();
}
Another way is to use one of the specialized LINQ to Entities operations, like DiffMinutes.