Export (0) Print
Expand All

ObjectQuery(Of T).Name Property

Gets or sets the name of this object query.

Namespace:  System.Data.Objects
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

'Declaration
Public Property Name As String

Property Value

Type: System.String
A string value that is the name of this ObjectQuery(Of T).

ExceptionCondition
ArgumentException

The value specified on set is not valid.

The name of the object query identifies the current object query in the sequence by name when constructing query builder methods. By default, the query name is it. This can be useful when referring to the current sequence in joins inside the Where method or in the SelectValue(Of TResultType) method. For more information, see Query Builder Methods (Entity Framework).

When you set the Name property of an ObjectQuery(Of T), that value becomes the alias in successive methods.

The value of the Name property must start with a letter and can contain letters, digits, and underscores.

This example sets the name of the first ObjectQuery(Of T) to "product" and then uses this alias in the successive OrderBy method. The example in this topic is based on the Adventure Works Sales Model.

' Return Product objects with a standard cost  
' above 10 dollars.  
Dim cost = 10
Dim productQuery As ObjectQuery(Of Product) = context.Products.Where("it.StandardCost > @cost")
productQuery.Parameters.Add(New ObjectParameter("cost", cost))

' Set the Name property for the query and then  
' use that name as the alias in the subsequent  
' OrderBy method. 
productQuery.Name = "product" 
Dim filteredProduct As ObjectQuery(Of Product) = productQuery.OrderBy("product.ProductID")

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft