ObjectQuery.Parameters 属性

定义

获取此对象查询的参数集合。

public:
 property System::Data::Objects::ObjectParameterCollection ^ Parameters { System::Data::Objects::ObjectParameterCollection ^ get(); };
public System.Data.Objects.ObjectParameterCollection Parameters { get; }
member this.Parameters : System.Data.Objects.ObjectParameterCollection
Public ReadOnly Property Parameters As ObjectParameterCollection

属性值

ObjectQuery<T> 的参数集合。

示例

此示例将新参数添加到 集合,然后获取此 ObjectQuery<T>的参数集合。 然后,该示例循环访问 ObjectParameterCollection 并显示集合中每个参数的名称、类型和值。

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

注解

使用返回的 ObjectParameterCollection 指定传递给查询的参数。 有关详细信息,请参阅 查询生成器方法

适用于

另请参阅