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
- Наследование
Примеры
Пример в этом разделе основан на модели AdventureWorks Sales.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. Дополнительные сведения см. в разделе ObjectParameterCollection.For 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() |
Возвращает объект Type для текущего экземпляра.Gets 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) |