DbFunction.DiffMinutes { 'System.NotSupportedException' }
DbFunction.DiffMinutes { 'System.NotSupportedException' }
我想写这段代码
我的这部分代码
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();
这部分 return 我这个
'DbFunctions.DiffMinutes(x.FB_CDate, x.FB_LTDate) > 20' threw an exception of type 'System.NotSupportedException'
DbFunctions 提供 CLR 方法,当在 LINQ to Entities 查询中使用时,这些方法会转换为 数据库函数 。
当您调用 ToList()
时,数据被加载到内存中并且 DbFunctions 导致错误。您需要按如下方式更改代码:
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();
我想写这段代码 我的这部分代码
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();
这部分 return 我这个
'DbFunctions.DiffMinutes(x.FB_CDate, x.FB_LTDate) > 20' threw an exception of type 'System.NotSupportedException'
DbFunctions 提供 CLR 方法,当在 LINQ to Entities 查询中使用时,这些方法会转换为 数据库函数 。
当您调用 ToList()
时,数据被加载到内存中并且 DbFunctions 导致错误。您需要按如下方式更改代码:
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();