ObjectQuery<T>.Where(String, ObjectParameter[]) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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)
Parameters
- predicate
- String
The filter predicate.
- parameters
- ObjectParameter[]
Zero or more parameters that are used in this method.
Returns
A new ObjectQuery<T> instance that is equivalent to the original instance with WHERE applied.
Exceptions
The predicate
is an empty string.
Examples
This 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);
}
}
Applies to
See also
Зворотний зв’язок
https://aka.ms/ContentUserFeedback.
Очікується незабаром: протягом 2024 року ми будемо припиняти використання механізму реєстрації проблем у GitHub для зворотного зв’язку щодо вмісту й замінювати його новою системою зворотного зв’язку. Докладніше:Надіслати й переглянути відгук про