2016-06-13 2 views
6

ObjectContext는 다음 동안NULL의 dbcontext에서 처리 내가 여기</p> <pre><code>from e in Employees where e.DesignationID !=558 select e </code></pre> <p><code>DesignationID</code>가 널 (NULL) 필드이 간단한 LINQ 쿼리가

SELECT 
[Extent1].[EmployeeID] AS [EmployeeID], 
[Extent1].[EmployeeCode] AS [EmployeeCode], 
[Extent1].[EmployeeName] AS [EmployeeName], 
[Extent1].[DesignationID] AS [DesignationID] 
FROM [dbo].[setupEmployees] AS [Extent1] 
WHERE 558 <> [Extent1].[DesignationID] 

:

objectcontext에서 쿼리에 번역을 dbcontext의 동일한 검색어는 다음 언어로 번역되었습니다.

SELECT 
    [Extent1].[EmployeeID] AS [EmployeeID], 
    [Extent1].[EmployeeCode] AS [EmployeeCode], 
    [Extent1].[EmployeeName] AS [EmployeeName], 
    [Extent1].[DesignationID] AS [DesignationID] 
    FROM [dbo].[setupEmployees] AS [Extent1] 
WHERE NOT ((558 = [Extent1].[DesignationID]) AND ([Extent1].[DesignationID] IS NOT NULL)) 

objectcontextdbcontext과 다르게 NULL을 처리합니까?

답변

3

이 동작은 구성 가능하므로 대부분 다른 기본값 (기본값이 다른 이유는 알 수 없음)의 문제 일 수 있습니다.

제어는 DbContextConfiguration.UseDatabaseNullSemantics 속성에 의해 제공된다 :

가져 널 또는 잠재적으로 두 가지 모두의 두 개의 피연산자를 비교했을 때 널 데이터베이스 의미론이 전시되어 있는지 여부를 나타내는 값을 설정한다. 기본값은 false입니다. UseDatabaseNullSemantics가 참인 경우 ((operand1 = operand2) AND (NOT (operand1 IS NULL OR operand2 IS NULL))))) 또는 ((operand1 IS NULL) AND (operand2 IS NULL)))를 반환합니다.

public YourDbContext() 
{ 
    // ... 
    this.Configuration.UseDatabaseNullSemantics = true; 
} 
:

당신이 (당신의 DB 컨텍스트 생성자 내에서 예를 들어) true로 설정해야 첫 번째 예에서와 같은 번역을 얻으려면
관련 문제