ObjectQuery<T>.Name 屬性

定義

取得或設定這個物件查詢的名稱。

public:
 property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
public string Name { get; set; }
member this.Name : string with get, set
Public Property Name As String

屬性值

string 值,為這個 ObjectQuery<T> 的名稱。

例外狀況

設定時所指定的值無效。

範例

這個範例會將第一個 ObjectQuery<T> 的名稱設定為 "product",然後在後續 OrderBy 方法中使用此別名。

int cost = 10;
// Return Product objects with a standard cost
// above 10 dollars.
ObjectQuery<Product> productQuery =
    context.Products
    .Where("it.StandardCost > @cost", 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";
ObjectQuery<Product> filteredProduct = productQuery
    .OrderBy("product.ProductID");

備註

建構查詢產生器方法時,物件查詢的名稱會依據名稱識別序列 (Sequence) 中的目前物件查詢。 根據預設,查詢名稱為 it。 在 Where 方法內部的聯結 (Join) 中或 SelectValue 方法中參考目前序列時,這可能會很有用。 如需詳細資訊,請參閱 查詢產生器方法

當您設定 NameObjectQuery<T> 屬性時,該值會變成後續方法中的別名 (Alias)。

Name 屬性的值必須以字母為開頭,而且可以包含字母、數字和底線。

適用於

另請參閱