반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

개발꿈나무

[LINQ] System.InvalidOperationException: The LINQ expression could not be translated. 본문

ERROR

[LINQ] System.InvalidOperationException: The LINQ expression could not be translated.

HYOKYE0NG 2021. 12. 1. 09:30
반응형

InvalidOperationException: The LINQ expression could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

 

 

Linq 쿼리에서 발생한 error

찾아보니 LINQ 쿼리에서 지원되는 않는 연산이 있어서 그런 것이라고 한다.

 

지원 및 미지원 LINQ 메서드 (LINQ to Entities) - ADO.NET

이 문서에서는 LINQ to Entities 쿼리에서 지원되고 지원되지 않는 표준 쿼리 연산자를 요약합니다.

docs.microsoft.com

 

위의 페이지에서 찾아보고 지원되지 않는 연산을 지우면 되지만

나는 지우고싶지 않아서

.AsQueryable()을 AsEnumerable()로 바꾸고, await-async를 제거했다.

그랬더니 제대로 실행되더라 ~~!~!

 

 

<기존 코드>

public async Task<List<W_DCN>> GetDCNList_Dashboard(int week_no, DateTime startdate)
{
    return await context.W_DCNS.AsQueryable()
                		        .OrderByDescending(f => f.DCN_NO)
                         		.Where(f => f.MODIFIED_DATE.Date > startdate && new TimeSpan(f.MODIFIED_DATE.Date.Ticks - startdate.Ticks).Days / 7 == week_no)
                         		.ToListAsync();
}

<수정 후 코드>

public List<W_DCN> GetDCNList_Dashboard(int week_no, DateTime startdate)
{
    return context.W_DCNS.AsEnumerable()
                         .OrderByDescending(f => f.DCN_NO)
                         .Where(f => f.MODIFIED_DATE.Date > startdate && new TimeSpan(f.MODIFIED_DATE.Date.Ticks - startdate.Ticks).Days / 7 == week_no)
                         .ToList();
}
반응형
Comments