ObjectParameter ObjectParameter ObjectParameter ObjectParameter Class

定义

表示传递给对象查询的查询参数。Represents a query parameter that is passed to an object query.

public ref class ObjectParameter sealed
public sealed class ObjectParameter
type ObjectParameter = class
Public NotInheritable Class ObjectParameter
继承
ObjectParameterObjectParameterObjectParameterObjectParameter

示例

本主题中的示例基于AdventureWorks 销售模型The example in this topic is based on the AdventureWorks Sales Model. 该示例向集合添加新参数。The example adds new parameters to the collection. 它循环访问 ObjectParameterCollection 并显示集合中每个参数的名称、类型和值。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;

    // Iterate through the ObjectParameterCollection.
    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

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

注解

表示传递给 ObjectQuery<T> 或查询生成器方法的查询参数。Represents a query parameter that is passed to an ObjectQuery<T> or a query builder method. 有关详细信息, 请参阅查询生成器方法For more information, see Query Builder Methods.

对象参数由名称、类型和值组成。Object parameters consist of a name, a type, and a value.

此类不能被继承。This class cannot be inherited. 有关详细信息,请参阅 ObjectParameterCollectionFor more information, see ObjectParameterCollection.

构造函数

ObjectParameter(String, Object) ObjectParameter(String, Object) ObjectParameter(String, Object) ObjectParameter(String, Object)

使用指定的名称和值初始化 ObjectParameter 类的新实例。Initializes a new instance of the ObjectParameter class with the specified name and value.

ObjectParameter(String, Type) ObjectParameter(String, Type) ObjectParameter(String, Type) ObjectParameter(String, Type)

用指定的名称和类型初始化 ObjectParameter 类的新实例。Initializes a new instance of the ObjectParameter class with the specified name and type.

属性

Name Name Name Name

获取参数名称,该名称只能通过构造函数进行设置。Gets the parameter name, which can only be set through a constructor.

ParameterType ParameterType ParameterType ParameterType

获取参数类型。Gets the parameter type.

Value Value Value Value

获取或设置参数值。Gets or sets the parameter value.

方法

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

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

(Inherited from Object)

适用于

另请参阅