ObjectQuery<T> 생성자

정의

ObjectQuery<T> 클래스의 새 인스턴스를 초기화합니다.

오버로드

Name Description
ObjectQuery<T>(String, ObjectContext)

지정된 Entity SQL 명령을 초기 쿼리로 사용하여 새 ObjectQuery<T> 인스턴스를 만듭니다.

ObjectQuery<T>(String, ObjectContext, MergeOption)

지정된 Entity SQL 명령을 초기 쿼리 및 지정된 병합 옵션으로 사용하여 새 ObjectQuery<T> 인스턴스를 만듭니다.

설명

스칼라 ObjectQuery<T> 결과의 컬렉션이 아닌 단일 스칼라 결과를 나타내는 방식으로 초기화할 수 있습니다. 일부 확장 메서드는 컬렉션 결과를 입력으로 요구합니다. 이 경우 ArgumentException 이러한 메서드 중 하나가 호출되면 throw됩니다. 자세한 내용은 개체 쿼리를 참조하세요.

애플리케이션이 런타임에 Entity SQL 쿼리를 생성하는 경우 데이터 원본의 명령 길이 제한 사항을 알고 있어야 합니다. 엔터티 SQL은 쿼리에서 명령 텍스트의 길이에 제한을 적용하지 않습니다.

ObjectQuery<T>(String, ObjectContext)

지정된 Entity SQL 명령을 초기 쿼리로 사용하여 새 ObjectQuery<T> 인스턴스를 만듭니다.

public:
 ObjectQuery(System::String ^ commandText, System::Data::Objects::ObjectContext ^ context);
public ObjectQuery(string commandText, System.Data.Objects.ObjectContext context);
new System.Data.Objects.ObjectQuery<'T> : string * System.Data.Objects.ObjectContext -> System.Data.Objects.ObjectQuery<'T>
Public Sub New (commandText As String, context As ObjectContext)

매개 변수

commandText
String

Entity SQL 쿼리입니다.

context
ObjectContext

ObjectContext 쿼리를 실행할 원본입니다.

예제

이 예제에서는 클래스의 인스턴스를 생성하는 방법을 보여 줍니다 ObjectQuery<T> .

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    // Call the constructor with a query for products and the ObjectContext.
    ObjectQuery<Product> productQuery1 =
        new ObjectQuery<Product>("Products", context);

    foreach (Product result in productQuery1)
        Console.WriteLine("Product Name: {0}", result.Name);

    string queryString =
        @"SELECT VALUE product FROM AdventureWorksEntities.Products AS product";

    // Call the constructor with the specified query and the ObjectContext.
    ObjectQuery<Product> productQuery2 =
        new ObjectQuery<Product>(queryString, context);

    foreach (Product result in productQuery2)
        Console.WriteLine("Product Name: {0}", result.Name);

    // Call the constructor with the specified query, the ObjectContext,
    // and the NoTracking merge option.
    ObjectQuery<Product> productQuery3 =
        new ObjectQuery<Product>(queryString,
            context, MergeOption.NoTracking);

    foreach (Product result in productQuery3)
        Console.WriteLine("Product Name: {0}", result.Name);
}

설명

애플리케이션이 런타임에 Entity SQL 쿼리를 생성하는 경우 데이터 원본의 명령 길이 제한 사항을 알고 있어야 합니다. 엔터티 SQL은 쿼리에서 명령 텍스트의 길이에 제한을 적용하지 않습니다.

추가 정보

적용 대상

ObjectQuery<T>(String, ObjectContext, MergeOption)

지정된 Entity SQL 명령을 초기 쿼리 및 지정된 병합 옵션으로 사용하여 새 ObjectQuery<T> 인스턴스를 만듭니다.

public:
 ObjectQuery(System::String ^ commandText, System::Data::Objects::ObjectContext ^ context, System::Data::Objects::MergeOption mergeOption);
public ObjectQuery(string commandText, System.Data.Objects.ObjectContext context, System.Data.Objects.MergeOption mergeOption);
new System.Data.Objects.ObjectQuery<'T> : string * System.Data.Objects.ObjectContext * System.Data.Objects.MergeOption -> System.Data.Objects.ObjectQuery<'T>
Public Sub New (commandText As String, context As ObjectContext, mergeOption As MergeOption)

매개 변수

commandText
String

Entity SQL 쿼리입니다.

context
ObjectContext

ObjectContext 쿼리를 실행할 원본입니다.

mergeOption
MergeOption

이 쿼리를 통해 검색된 엔터티를 이전 ObjectContext쿼리에서 동일한 항목에 대해 반환된 엔터티와 병합하는 방법을 지정합니다.

예제

이 예제에서는 ObjectQuery<T> 지정된 쿼리 ObjectContext를 사용하여 초기화됩니다 MergeOption.

int productID = 900;
using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    string queryString = @"SELECT VALUE product FROM
        AdventureWorksEntities.Products AS product
        WHERE product.ProductID > @productID";

    ObjectQuery<Product> productQuery1 =
        new ObjectQuery<Product>(queryString,
            context, MergeOption.NoTracking);

    productQuery1.Parameters.Add(new ObjectParameter("productID", productID));

    ObjectQuery<DbDataRecord> productQuery2 =
        productQuery1.Select("it.ProductID");

    foreach (DbDataRecord result in productQuery2)
    {
        Console.WriteLine("{0}", result["ProductID"]);
    }
}

설명

애플리케이션이 런타임에 Entity SQL 쿼리를 생성하는 경우 데이터 원본의 명령 길이 제한 사항을 알고 있어야 합니다. 엔터티 SQL은 쿼리에서 명령 텍스트의 길이에 제한을 적용하지 않습니다.

적용 대상