본문 바로가기

DB/Entity Framework

DbArithmeticExpression arguments must have a numeric common type



유발 소스


var attachFileList = context.AttachFile.Where(x => x.CHECK_DATE.Equals(null) || ( !x.CHECK_DATE.Equals(null) && ((TimeSpan)(DateTime.Now – (DateTime)x.CHECK_DATE)).TotalDays > 30 )).ToList();

-> DbArithmeticExpression arguments must have a numeric common type


where 조건절에서 datetime 과 datetime 간의 diff 을 수행하려는 구문에 발생합니다.


Mssql sp 에서는 문제없이 수행되는 구문이지만 EntityFramework 에서는 조건절의 Datetime 직접 비교는 지원하지않습니다.


Arithmetic with DateTime is not supported in Entity Framework. You have to use DbFunctions*. So, for the first part of your statement, something like:


수정소스


var attachFileList = context.AttachFile.Where(x => x.CHECK_DATE.Equals(null) || (!x.CHECK_DATE.Equals(null) && DbFunctions.DiffMonths(DateTime.Now, x.CHECK_DATE) > 1 )).ToList();