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

筛选谓词。

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);
    }
}

适用于

另请参阅