2017-12-29 15 views
1

이 저장 프로 시저에이 사용자 지정 열이 있습니다. 당신이 볼 수 있듯이, 그 값이 그 어느 null이 될 것입니다 방법이 없습니다 : 괜찮 enter image description here엔티티 프레임 워크 CASE-WHEN 열이 nullable이 될 수 없음

을하지만 난에 있습니다 : 내가 엔티티 프레임 워크에 매핑 할 때

cast(case when (s.userName is not null and s.Username in ('super','superadmin') then 1 
    else 0 end 
    as bit) as isSuperAdmin 

를, 그것은 Null 허용으로 전환 다음을 수행하고 추한 :

var isSuperAdmin = (!user.isSuperAdmin.HasValue) ? false: user.isSuperAdmin.Value; 

Boolean 값을로 강제 할 수있는 방법이있다? ISNULL

에 싸여이

ISNULL(CASE WHEN s.Username in ('super','superadmin') THEN CAST(1 AS BIT) END,0) as isSuperAdmin 

s.userName is not null 검사에 대한 필요가 없습니다 일을해야하지 않는 한

답변

2

SQL Server는 널 (NULL) 대부분의 계산 된 식의 값을 처리합니다. IN과 일치하면 NULL이되지 않습니다.

관련 문제