Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the ObjectParameter class.
ObjectParameter(String, Object) |
Initializes a new instance of the ObjectParameter class with the specified name and value. |
ObjectParameter(String, Type) |
Initializes a new instance of the ObjectParameter class with the specified name and type. |
Initializes a new instance of the ObjectParameter class with the specified name and value.
public:
ObjectParameter(System::String ^ name, System::Object ^ value);
public ObjectParameter(string name, object value);
new System.Data.Objects.ObjectParameter : string * obj -> System.Data.Objects.ObjectParameter
Public Sub New (name As String, value As Object)
The parameter name. This name should not include the "@" parameter marker that is used in Entity SQL statements, only the actual name. The first character of the expression must be a letter. Any successive characters in the expression must be either letters, numbers, or an underscore (_) character.
The initial value (and inherently, the type) of the parameter.
If the value of either argument is null.
If the value of the name argument is not valid. Parameter names must start with a letter and can only contain letters, numbers, and underscores.
This example adds new parameters to the collection. It iterates through the ObjectParameterCollection and displays the name, the type and the 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);
}
}
This constructor creates a parameter from the specified name and value. The type of the parameter is inferred from the value.
When added to the ObjectParameterCollection, the parameter name cannot be changed. The parameter value can be changed through the Value property. After the query has been compiled, the value cannot be changed. For more information, see Query Builder Methods.
Product | Versions |
---|---|
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Initializes a new instance of the ObjectParameter class with the specified name and type.
public:
ObjectParameter(System::String ^ name, Type ^ type);
public ObjectParameter(string name, Type type);
new System.Data.Objects.ObjectParameter : string * Type -> System.Data.Objects.ObjectParameter
Public Sub New (name As String, type As Type)
The parameter name. This name should not include the "@" parameter marker that is used in the Entity SQL statements, only the actual name. The first character of the expression must be a letter. Any successive characters in the expression must be either letters, numbers, or an underscore (_) character.
The common language runtime (CLR) type of the parameter.
If the value of either argument is null.
If the value of the name argument is invalid. Parameter names must start with a letter and can only contain letters, numbers, and underscores.
When instantiated, the parameter name cannot be changed. The parameter value can be set or changed through the Value property. After the query has been compiled, the value cannot be changed. For more information, see Query Builder Methods.
Product | Versions |
---|---|
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in