Share via


방법: 지연된 로드 해제(LINQ to SQL)

업데이트: November 2007

DeferredLoadingEnabled를 false로 설정하여 지연된 로드를 해제할 수 있습니다. 자세한 내용은 지연된 로드와 즉시 로드 비교(LINQ to SQL)를 참조하십시오.

참고:

개체 추적이 해제되면 지연된 로드는 암시적으로 해제된 것입니다. 자세한 내용은 방법: 정보를 읽기 전용으로 검색(LINQ to SQL)을 참조하십시오.

예제

다음 예제에서는 DeferredLoadingEnabled를 false로 설정하여 지연된 로드를 해제하는 방법을 보여 줍니다.

Dim db As New Northwnd("c:\northwnd.mdf")

db.DeferredLoadingEnabled = False

Dim ds As New DataLoadOptions()
ds.LoadWith(Function(c As Customer) c.Orders)
ds.LoadWith(Of Order)(Function(o) o.OrderDetails)
db.LoadOptions = ds

Dim custQuery = From cust In db.Customers _
    Where cust.City = "London" _
    Select cust

For Each custObj In custQuery
    Console.WriteLine("Customer ID: {0}", custObj.CustomerID)
    For Each ord In custObj.Orders
        Console.WriteLine(vbTab & "Order ID: {0}", ord.OrderID)
        For Each detail In ord.OrderDetails
            Console.WriteLine(vbTab & vbTab & "Product ID: {0}", _
                detail.ProductID)
        Next
    Next
Next
Northwnd db = new Northwnd(@"c:\northwnd.mdf");
db.DeferredLoadingEnabled = false;

DataLoadOptions ds = new DataLoadOptions();
ds.LoadWith<Customer>(c => c.Orders);
ds.LoadWith<Order>(o => o.OrderDetails);
db.LoadOptions = ds;

var custQuery =
    from cust in db.Customers
    where cust.City == "London"
    select cust;

foreach (Customer custObj in custQuery)
{
    Console.WriteLine("Customer ID: {0}", custObj.CustomerID);
    foreach (Order ord in custObj.Orders)
    {
        Console.WriteLine("\tOrder ID: {0}", ord.OrderID);
        foreach (OrderDetail detail in ord.OrderDetails)
        {
            Console.WriteLine("\t\tProduct ID: {0}", detail.ProductID);
        }
    }
}

참고 항목

기타 리소스

LINQ to SQL의 쿼리 개념

데이터베이스 쿼리(LINQ to SQL)