共用方式為


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

定義

將查詢限制為符合指定之篩選準則的結果。

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

篩選述詞 (Predicate)。

parameters
ObjectParameter[]

這個方法所使用的零個或多個參數。

傳回

新的 ObjectQuery<T> 執行個體,它就相當於套用了 WHERE 的原始執行個體。

例外狀況

predicatenull

-或-

parametersnull

predicate 為空字串。

範例

此範例會建立新的 ObjectQuery<T> ,其中包含下列準則篩選的現有查詢結果: "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);
    }
}

適用於

另請參閱