일부 코드를 Entity Framework를 사용하도록 마이그레이션하고 Nullable 필드를 정렬하려고하는 쿼리가 있고 기본 정렬 값을 제공하는 값은 null입니다. Nullable.GetValueOrDefault(T) 기능.OrderBy on Nullable <int>에 Entity Framework의 기본값으로
그러나, 실행시 다음과 같은 오류를 반환합니다 this answer I can see that there is a way to provide "translations" within your EDMX에서
int magicDefaultSortValue = 250;
var query = context.MyTable.OrderBy(t => t.MyNullableSortColumn
.GetValueOrDefault(magicDefaultSortValue));
:
LINQ to Entities does not recognize the method 'Int32 GetValueOrDefault(Int32)' method, and this method cannot be translated into a store expression.
쿼리처럼 보인다. 이 통합 함수에 대해 비슷한 번역을 쓸 수 있을까요?
참고 : 시도 할 때 ??
쿼리가 GetValueOrDefault 대신 작동하는 병합 연산자가 작동합니다. 그럼 아마 그 일을하는 것은 무엇이든 활용 될 수 있을까요?
고마워요! 그러나'?? '가 작동하는 것을 발견 한 후에 이미 GetValueOrDefault()를 사용하고 있던 기존 쿼리 (LINQ To SQL 컨텍스트에 대해 작성된)를 편집하지 않아도되기를 바랬습니다. – Reddog