ObjectParameterCollection ObjectParameterCollection ObjectParameterCollection ObjectParameterCollection Class

Definition

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)
Inheritance
ObjectParameterCollectionObjectParameterCollectionObjectParameterCollectionObjectParameterCollection
Implements

Examples

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. 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

Remarks

Represents the query parameters as ObjectParameter objects defined in an ObjectQuery<T>.

This class cannot be inherited.

The parameters that are passed to query builder methods are aggregated by successive instances of an ObjectQuery<T> in the sequence. 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.

Parameters must be unique in the ObjectParameterCollection. There cannot be two parameters in the collection with the same name.

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.

Properties

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.

Methods

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

Adds the specified ObjectParameter to the collection.

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

Deletes all ObjectParameter instances from the collection.

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

Checks for the existence of a specified ObjectParameter in the collection by reference.

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

Determines 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()

Gets the Type of the current instance.

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

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(ObjectParameter) Remove(ObjectParameter) Remove(ObjectParameter) Remove(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)

Explicit Interface Implementations

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.

Extension Methods

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

Returns 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)

Copies 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)

Copies 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)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(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)

Converts 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. 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. 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. 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.

Applies to

See also