ObjectQuery<T>.Include(String) Yöntem

Tanım

Sorgu sonuçlarına eklenecek ilgili nesneleri belirtir.

public:
 System::Data::Objects::ObjectQuery<T> ^ Include(System::String ^ path);
public System.Data.Objects.ObjectQuery<T> Include (string path);
member this.Include : string -> System.Data.Objects.ObjectQuery<'T>
Public Function Include (path As String) As ObjectQuery(Of T)

Parametreler

path
String

Sorgu sonuçlarında döndürülecek ilişkili nesnelerin noktalı olarak ayrılmış listesi.

Döndürülenler

Tanımlı sorgu yolunu içeren yeni ObjectQuery<T> bir.

Özel durumlar

path, null değeridir.

path, empty değeridir.

Örnekler

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    // Define an object query with a path that returns
    // orders and items for a specific contact.
    Contact contact =
        context.Contacts.Include("SalesOrderHeaders.SalesOrderDetails")
        .FirstOrDefault();

    // Execute the query and display information for each item
    // in the orders that belong to the first contact.
    foreach (SalesOrderHeader order in contact
        .SalesOrderHeaders)
    {
        Console.WriteLine(String.Format("PO Number: {0}",
            order.PurchaseOrderNumber));
        Console.WriteLine(String.Format("Order Date: {0}",
            order.OrderDate.ToString()));
        Console.WriteLine("Order items:");
        foreach (SalesOrderDetail item in order.SalesOrderDetails)
        {
            Console.WriteLine(String.Format("Product: {0} "
                + "Quantity: {1}", item.ProductID.ToString(),
                item.OrderQty.ToString()));
        }
    }
}

Açıklamalar

Sorgu yolları, Entity SQL ve LINQ sorgularıyla kullanılabilir.

Yollar her şey dahil. Örneğin, bir include çağrısı gösteriyorsa Include("Orders.OrderLines"), yalnızca OrderLines dahil değil, aynı zamanda Ordersda eklenir. Daha fazla bilgi için bkz . İlgili Nesneleri Yükleme.

yöntemini çağırdığınızda Include sorgu yolu yalnızca döndürülen örneğinde ObjectQuery<T>geçerlidir. ve nesne bağlamının diğer örnekleri ObjectQuery<T> etkilenmez.

Include yöntemi sorgu nesnesini döndürdüğünden, aşağıdaki örnekte olduğu gibi sorgu için birden çok yol belirtmek üzere bu yöntemi üzerinde ObjectQuery<T> birden çok kez çağırabilirsiniz:

// Create a SalesOrderHeader query with two query paths,
// one that returns order items and a second that returns the
// billing and shipping addresses for each order.
ObjectQuery<SalesOrderHeader> query =
    context.SalesOrderHeaders.Include("SalesOrderDetails").Include("Address");

Şunlara uygulanır

Ayrıca bkz.