Share via


방법: 생성된 SQL 표시(LINQ to SQL)

업데이트: November 2007

Log 속성을 사용하여 쿼리에 대해 생성된 SQL 코드를 보고 프로세스를 변경할 수 있습니다. 이러한 접근 방식은 LINQ to SQL 기능을 이해하고 특정 문제를 디버깅하는 데 유용합니다.

예제

다음 예제에서는 Log 속성을 사용하여 코드를 실행하기 전에 콘솔 창에 SQL 코드를 표시합니다. 이 속성은 쿼리, 삽입, 업데이트 및 삭제 명령과 함께 사용할 수 있습니다.

콘솔 창의 줄은 다음 Visual Basic 또는 C# 코드를 실행했을 때 표시되는 줄입니다.

SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactT

itle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Coun

try], [t0].[Phone], [t0].[Fax]

FROM [dbo].[Customers] AS [t0]

WHERE [t0].[City] = @p0

-- @p0: Input String (Size = 6; Prec = 0; Scale = 0) [London]

-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.20810.0

AROUT

BSBEV

CONSH

EASTC

NORTS

SEVES

db.Log = Console.Out
Dim custQuery = _
    From cust In db.Customers _
    Where cust.City = "London" _
    Select cust

For Each custObj In custQuery
    Console.WriteLine(custObj.CustomerID)
Next
db.Log = Console.Out;
IQueryable<Customer> custQuery =
    from cust in db.Customers
    where cust.City == "London"
    select cust;

foreach(Customer custObj in custQuery)
{
    Console.WriteLine(custObj.CustomerID);
}

참고 항목

기타 리소스

디버깅 지원(LINQ to SQL)