DataContext.GetCommand(IQueryable) 메서드

정의

LINQ to SQL 생성된 SQL 명령에 대한 정보를 가져옵니다.

public:
 System::Data::Common::DbCommand ^ GetCommand(System::Linq::IQueryable ^ query);
public System.Data.Common.DbCommand GetCommand (System.Linq.IQueryable query);
member this.GetCommand : System.Linq.IQueryable -> System.Data.Common.DbCommand
Public Function GetCommand (query As IQueryable) As DbCommand

매개 변수

query
IQueryable

SQL 명령 정보를 검색할 쿼리입니다.

반환

요청된 명령 정보 개체입니다.

예제

// using System.Data.Common;
Northwnd db = new Northwnd(@"c:\northwnd.mdf");

var q =
    from cust in db.Customers
    where cust.City == "London"
    select cust;

Console.WriteLine("Customers from London:");
foreach (var z in q)
{
    Console.WriteLine("\t {0}",z.ContactName);
}

DbCommand dc = db.GetCommand(q);
Console.WriteLine("\nCommand Text: \n{0}",dc.CommandText);
Console.WriteLine("\nCommand Type: {0}",dc.CommandType);
Console.WriteLine("\nConnection: {0}",dc.Connection);

Console.ReadLine();
' Imports System.Data.Common

Dim db As New Northwnd("c:\northwnd.mdf")

Dim q = _
From cust In db.Customers _
Where cust.City = "London" _
Select cust

Console.WriteLine("Customers from London:")
For Each z As Customer In q
    Console.WriteLine(vbTab & z.ContactName)
Next

Dim dc As DbCommand = db.GetCommand(q)
Console.WriteLine(Environment.NewLine & "Command Text: " & Environment.NewLine & dc.CommandText)
Console.WriteLine(Environment.NewLine & "Command Type: {0}", dc.CommandType)
Console.WriteLine(Environment.NewLine & "Connection: {0}", dc.Connection)

Console.ReadLine()

설명

이 메서드는 getter일 뿐이며 상태에 영향을 DataContext 주지 않습니다.

다음 고려 사항에 유의하세요.

  • 인수는 null이 아니어야 합니다. 그렇지 않으면 null 인수 예외를 throw 됩니다.

  • LINQ to SQL 쿼리 실행 중에 throw된 일반 쿼리 변환 예외는 번역할 수 없는 쿼리에 적용됩니다.

  • 첫 번째 쿼리 명령만 반환됩니다. 특히 즉시 로드(LoadWith)에 사용되는 추가 명령은 포함되지 않습니다.

  • DataContext 는 사용자가 명령을 사용하여 수행하는 작업을 추적하지 않습니다. 예를 들어 반환된 명령의 실행 결과는 추적되지 않으며 상태에 영향을 DataContext 미치지 않습니다.

적용 대상