ObjectParameterCollection ObjectParameterCollection ObjectParameterCollection ObjectParameterCollection Class

定义

将查询参数表示为 ObjectParameter 中定义的 ObjectQuery<T> 对象。Represents the query parameters as ObjectParameter objects that are defined in an ObjectQuery<T>.

public ref class ObjectParameterCollection sealed : System::Collections::Generic::ICollection<System::Data::Objects::ObjectParameter ^>, System::Collections::Generic::IEnumerable<System::Data::Objects::ObjectParameter ^>
public sealed class ObjectParameterCollection : System.Collections.Generic.ICollection<System.Data.Objects.ObjectParameter>, System.Collections.Generic.IEnumerable<System.Data.Objects.ObjectParameter>
type ObjectParameterCollection = class
    interface ICollection<ObjectParameter>
    interface seq<ObjectParameter>
    interface IEnumerable
Public NotInheritable Class ObjectParameterCollection
Implements ICollection(Of ObjectParameter), IEnumerable(Of ObjectParameter)
继承
ObjectParameterCollectionObjectParameterCollectionObjectParameterCollectionObjectParameterCollection
实现

示例

本主题中的示例基于AdventureWorks 销售模型The example in this topic is based on the AdventureWorks Sales Model. 该示例将新参数添加到集合,获取集合中的参数个数。The example adds new parameters to the collection and gets the count of the parameters in the collection. 然后,该示例循环访问 ObjectParameterCollection 并显示集合中每个参数的名称、类型和值。Then it iterates through the ObjectParameterCollection and displays the name, type, and value of each parameter in the collection.

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    string queryString =
        @"SELECT VALUE contact FROM AdventureWorksEntities.Contacts 
        AS contact WHERE contact.LastName = @ln AND contact.FirstName = @fn";

    ObjectQuery<Contact> contactQuery =
        new ObjectQuery<Contact>(queryString, context);

    // Add parameters to the collection.
    contactQuery.Parameters.Add(new ObjectParameter("ln", "Adams"));
    contactQuery.Parameters.Add(new ObjectParameter("fn", "Frances"));

    ObjectParameterCollection objectParameterCollection =
        contactQuery.Parameters;

    Console.WriteLine("Count is {0}.", objectParameterCollection.Count);

    // Iterate through the ObjectParameterCollection collection.
    foreach (ObjectParameter result in objectParameterCollection)
    {
        Console.WriteLine("{0} {1} {2}", result.Name,
            result.Value,
            result.ParameterType);
    }
}
Using context As New AdventureWorksEntities()
    Dim queryString As String = "SELECT VALUE contact FROM AdventureWorksEntities.Contacts " & _
            " AS contact WHERE contact.LastName = @ln AND contact.FirstName = @fn"

    Dim contactQuery As New ObjectQuery(Of Contact)(queryString, context)

    ' Add parameters to the collection. 
    contactQuery.Parameters.Add(New ObjectParameter("ln", "Adams"))
    contactQuery.Parameters.Add(New ObjectParameter("fn", "Frances"))

    Dim objectParameterCollection As ObjectParameterCollection = contactQuery.Parameters

    Console.WriteLine("Count is {0}.", objectParameterCollection.Count)

    ' Iterate through the ObjectParameterCollection collection. 
    For Each result As ObjectParameter In objectParameterCollection
        Console.WriteLine("{0} {1} {2}", result.Name, result.Value, result.ParameterType)
    Next
End Using

注解

将查询参数表示为 ObjectParameter 中定义的 ObjectQuery<T> 对象。Represents the query parameters as ObjectParameter objects defined in an ObjectQuery<T>.

此类不能被继承。This class cannot be inherited.

传递给查询生成器方法的参数由序列中 ObjectQuery<T> 的后续实例聚合。The parameters that are passed to query builder methods are aggregated by successive instances of an ObjectQuery<T> in the sequence. 可以使用返回 ParametersObjectParameterCollection 属性访问这些参数。They can be accessed by using the Parameters property, which returns the ObjectParameterCollection. 添加参数后,只要还没有编译或执行查询,就可以从集合中移除参数,并且可以清除集合。After parameters have been added, they can be removed from the collection and the collection can be cleared, as long as the query has not been compiled or executed. 不能更改参数名称,但可以随时对值进行更改。Parameter names cannot be changed, but values can be changed at any time.

参数在 ObjectParameterCollection 中必须是唯一的。Parameters must be unique in the ObjectParameterCollection. 集合中不能有两个具有相同名称的参数。There cannot be two parameters in the collection with the same name.

使用组合方法(如 UnionUnionAllIntersectExcept)时,将对参数进行合并。When using composition methods, such as Union, UnionAll, Intersect and Except, the parameters are merged. 参数集不兼容或不完整时会引发异常。An exception is thrown when the sets of parameters are incompatible or incomplete. 有关详细信息, 请参阅查询生成器方法For more information, see Query Builder Methods.

属性

Count Count Count Count

获取集合中当前存在的参数的数量。Gets the number of parameters currently in the collection.

Item[String] Item[String] Item[String] Item[String]

提供一个索引器,供调用方按名称检索参数。Provides an indexer that allows callers to retrieve parameters by name.

方法

Add(ObjectParameter) Add(ObjectParameter) Add(ObjectParameter) Add(ObjectParameter)

将指定的 ObjectParameter 添加到集合。Adds the specified ObjectParameter to the collection.

Clear() Clear() Clear() Clear()

删除集合中的所有 ObjectParameter 实例。Deletes all ObjectParameter instances from the collection.

Contains(ObjectParameter) Contains(ObjectParameter) Contains(ObjectParameter) Contains(ObjectParameter)

按引用检查集合中是否存在指定的 ObjectParameterChecks for the existence of a specified ObjectParameter in the collection by reference.

Contains(String) Contains(String) Contains(String) Contains(String)

确定集合中是否存在具有指定名称的 ObjectParameterDetermines whether an ObjectParameter with the specified name is in the collection.

CopyTo(ObjectParameter[], Int32) CopyTo(ObjectParameter[], Int32) CopyTo(ObjectParameter[], Int32) CopyTo(ObjectParameter[], Int32)

允许将集合中的参数复制到提供的数组中(从指定索引处的对象开始)。Allows the parameters in the collection to be copied into a supplied array, starting with the object at the specified index.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(ObjectParameter) Remove(ObjectParameter) Remove(ObjectParameter) Remove(ObjectParameter)

按引用从集合中移除 ObjectParameter 的实例(如果集合中存在该实例)。Removes an instance of an ObjectParameter from the collection by reference if it exists in the collection.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

ICollection<ObjectParameter>.IsReadOnly ICollection<ObjectParameter>.IsReadOnly ICollection<ObjectParameter>.IsReadOnly ICollection<ObjectParameter>.IsReadOnly

获取一个值,该值指示集合是只读的还是可修改的。Gets a value that indicates whether the collection is read-only or can be modified.

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

返回集合上的非类型化枚举器。Returns an untyped enumerator over the collection.

IEnumerable<ObjectParameter>.GetEnumerator() IEnumerable<ObjectParameter>.GetEnumerator() IEnumerable<ObjectParameter>.GetEnumerator() IEnumerable<ObjectParameter>.GetEnumerator()

返回集合上的类型化枚举器。Returns a typed enumerator over the collection.

扩展方法

CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

在给定其泛型参数 TDataTable 的输入 DataRow 对象的情况下,返回包含 IEnumerable<T> 对象副本的 DataRowReturns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个节点的上级。Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个节点的上级。Returns a filtered collection of elements that contains the ancestors of every node in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子代节点的集合。Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>)

返回源集合中每个元素和文档的子元素的集合。Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName)

返回源集合中经过筛选的每个元素和文档的子元素集合。Returns a filtered collection of the child elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>)

返回节点集合(其中包含源集合中的所有节点),并按文档顺序排列。Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子节点集合。Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

将源集合中的每个节点从其父节点中移除。Removes every node in the source collection from its parent node.

适用于

另请参阅