-2

I want write this code this part of my code

    var today = DateTime.Now;
    var todayString = today.ToShortDateString();
    List<FB> fBList = _context.FBs.ToList();
    fBList = fBList.Where(x => DbFunctions.DiffMinutes(x.FB_CDate, x.FB_LTDate) > 20 ).ToList();

and this part return me this

    'DbFunctions.DiffMinutes(x.FB_CDate, x.FB_LTDate) > 20' threw an exception of type 'System.NotSupportedException'
Józef Podlecki
  • 10,453
  • 5
  • 24
  • 50

1 Answers1

4

DbFunctions provides CLR methods that get translated to database functions when used in LINQ to Entities queries. When you call ToList(),data is loaded into memory and DbFunctions causes an error. You need to change your code as follows:

 var today = DateTime.Now;
            var todayString = today.ToShortDateString();
            List<FB> fBList = _context.FBs.Where(x => DbFunctions.DiffMinutes(x.FB_CDate, x.FB_LTDate) > 20).ToList();
vahid tajari
  • 1,163
  • 10
  • 20
  • Delete the fourth line and change the third line to `List fBList = _context.FBs.Where(x => DbFunctions.DiffMinutes(x.FB_CDate, x.FB_LTDate) > 20).ToList();` – vahid tajari Jun 21 '20 at 12:03