ObjectQuery<T>.Where(String, ObjectParameter[]) ObjectQuery<T>.Where(String, ObjectParameter[]) ObjectQuery<T>.Where(String, ObjectParameter[]) ObjectQuery<T>.Where(String, ObjectParameter[]) Method

定義

指定されたフィルター条件と一致する結果となるようにクエリを制限します。Limits the query to results that match specified filtering criteria.

public:
 System::Data::Objects::ObjectQuery<T> ^ Where(System::String ^ predicate, ... cli::array <System::Data::Objects::ObjectParameter ^> ^ parameters);
public System.Data.Objects.ObjectQuery<T> Where (string predicate, params System.Data.Objects.ObjectParameter[] parameters);
member this.Where : string * System.Data.Objects.ObjectParameter[] -> System.Data.Objects.ObjectQuery<'T>
Public Function Where (predicate As String, ParamArray parameters As ObjectParameter()) As ObjectQuery(Of T)

パラメーター

predicate
String String String String

フィルター述語。The filter predicate.

parameters
ObjectParameter[]

このメソッドで使用される 0 個以上のパラメーター。Zero or more parameters that are used in this method.

戻り値

WHERE が適用された元のインスタンスに相当する、新しい ObjectQuery<T> インスタンス。A new ObjectQuery<T> instance that is equivalent to the original instance with WHERE applied.

例外

predicatenullです。predicate is null.

- または --or- parametersnullです。parameters is null.

predicate が空の文字列です。The predicate is an empty string.

この例は、 AdventureWorks Sales Modelに基づいています。This example is based on the AdventureWorks Sales Model. この例では、ObjectQuery<T> という条件でフィルターされた既存のクエリの結果を含む "it.ProductID = 900" を新たに作成します。The example creates a new ObjectQuery<T> that contains results of the existing query filtered by the following criteria: "it.ProductID = 900".

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

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

    ObjectQuery<Product> productQuery2 =
        productQuery1.Where("it.ProductID = @productID");

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

    // Iterate through the collection of Product items.
    foreach (Product result in productQuery2)
    {
        Console.WriteLine("Product Name: {0}; Product ID: {1}",
            result.Name, result.ProductID);
    }
}
Dim productID = 900
Using context As New AdventureWorksEntities()
    Dim queryString As String = "SELECT VALUE product FROM AdventureWorksEntities.Products AS product"

    Dim productQuery1 As New ObjectQuery(Of Product)(queryString, context, MergeOption.NoTracking)

    Dim productQuery2 As ObjectQuery(Of Product) = productQuery1.Where("it.ProductID = @productID")
    productQuery2.Parameters.Add(New ObjectParameter("productID", productID))

    ' Iterate through the collection of Product items. 
    For Each result As Product In productQuery2
        Console.WriteLine("Product Name: {0}; Product ID: {1}", result.Name, result.ProductID)
    Next
End Using

適用対象

こちらもご覧ください