DataLoadOptions.LoadWith 메서드

정의

오버로드

LoadWith(LambdaExpression)

람다 식을 사용하여 주 대상에 관련된 지정된 데이터를 검색합니다.

LoadWith<T>(Expression<Func<T,Object>>)

T 형식의 개체에 대한 쿼리가 전송될 때 검색되는 하위 개체를 지정합니다.

LoadWith(LambdaExpression)

람다 식을 사용하여 주 대상에 관련된 지정된 데이터를 검색합니다.

public:
 void LoadWith(System::Linq::Expressions::LambdaExpression ^ expression);
public void LoadWith (System.Linq.Expressions.LambdaExpression expression);
member this.LoadWith : System.Linq.Expressions.LambdaExpression -> unit
Public Sub LoadWith (expression As LambdaExpression)

매개 변수

expression
LambdaExpression

관련 자료를 식별하는 람다 식입니다.

예제

Northwnd db = new Northwnd(@"c:\northwnd.mdf");
DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith<Customer>(c => c.Orders);
db.LoadOptions = dlo;

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

foreach (var custObj in londonCustomers)
{
    Console.WriteLine(custObj.CustomerID);
}
Dim db As New Northwnd("c:\northwnd.mdf")

Dim dlo As DataLoadOptions = New DataLoadOptions()
dlo.LoadWith(Of Customer)(Function(c As Customer) c.Orders)
db.LoadOptions = dlo

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

For Each custObj In londonCustomers
    Console.WriteLine(custObj.CustomerID)
Next

설명

다음 예제에서는 런던에 있는 모든 Customers에 대한 모든 Orders가 쿼리가 실행될 때 검색됩니다. 따라서 Customer 개체의 Orders 속성에 대한 연속 액세스는 새 데이터베이스 쿼리를 트리거하지 않습니다.

적용 대상

LoadWith<T>(Expression<Func<T,Object>>)

T 형식의 개체에 대한 쿼리가 전송될 때 검색되는 하위 개체를 지정합니다.

public:
generic <typename T>
 void LoadWith(System::Linq::Expressions::Expression<Func<T, System::Object ^> ^> ^ expression);
public void LoadWith<T> (System.Linq.Expressions.Expression<Func<T,object>> expression);
member this.LoadWith : System.Linq.Expressions.Expression<Func<'T, obj>> -> unit
Public Sub LoadWith(Of T) (expression As Expression(Of Func(Of T, Object)))

형식 매개 변수

T

쿼리 대상 형식입니다.

이 형식이 매핑되지 않은 경우 예외가 throw됩니다.

매개 변수

expression
Expression<Func<T,Object>>

검색할 필드 또는 속성을 식별합니다.

식이 일대일 또는 일대다 관계를 나타내는 필드 또는 속성을 식별하지 않으면 예외가 throw됩니다.

예제

다음 예제에서는 런던에 있는 모든 Customers에 대한 모든 Orders가 쿼리가 실행될 때 검색됩니다. 따라서 Customer 개체의 Orders 속성에 대한 연속 액세스는 새 데이터베이스 쿼리를 트리거하지 않습니다.

Northwnd db = new Northwnd(@"c:\northwnd.mdf");
DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith<Customer>(c => c.Orders);
db.LoadOptions = dlo;

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

foreach (var custObj in londonCustomers)
{
    Console.WriteLine(custObj.CustomerID);
}
Dim db As New Northwnd("c:\northwnd.mdf")

Dim dlo As DataLoadOptions = New DataLoadOptions()
dlo.LoadWith(Of Customer)(Function(c As Customer) c.Orders)
db.LoadOptions = dlo

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

For Each custObj In londonCustomers
    Console.WriteLine(custObj.CustomerID)
Next

설명

두 수준의 관계(예 Orders.OrderDetails: )의 로드를 지정할 수 없습니다. 이러한 시나리오에서는 두 개의 별도 LoadWith 메서드를 지정해야 합니다.

순환을 방지하려면 의 주의 섹션을 DataLoadOptions참조하세요.

적용 대상