여기에 약간의 LinqToSql 잡았다는 다음과 같습니다조건부 바로 가기
// Returns the number of counties in a state,
// or all counties in the USA if the state is null
public static int CountCounties(State s) {
var q =
from cy in County.GetTable() // my method to get the ITable
where (s == null || s.Code == cy.StateCode) // shortcut OR operator, right...?
select cy;
return q.Count();
}
무엇을 추측 -이 방법에 널 State
개체를 전달할 경우, 당신은 null 참조 예외를 얻을! LinqToSql은 바로 가기로 ||
바로 가기 연산자를 사용하지 않는 것 같습니다!
답 신용은 가장 좋은 설명 인 & 해결 방법을 제안합니다.
이 LinqToSql입니까? –
'정상적인'Linq 비슷한 쿼리가 나를 위해 잘 작동합니다. –
예, LinqToSql입니다. - 죄송합니다. 질문을 편집 할 것입니다. –