Share via


DataLoadOptions.AssociateWith 메서드

정의

오버로드

AssociateWith(LambdaExpression)

특정 관계에 대해 검색한 개체를 필터링합니다.

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

특정 관계에 대해 검색한 개체를 필터링합니다.

AssociateWith(LambdaExpression)

특정 관계에 대해 검색한 개체를 필터링합니다.

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

매개 변수

expression
LambdaExpression

특정 일대다 필드 또는 속성에 사용할 쿼리를 식별합니다. 다음 사항에 유의하십시오.

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

유효한 연산자가 아닌 연산자가 식에 나타나면 예외가 throw됩니다. 유효한 연산자는 다음과 같습니다.

Where

OrderBy

ThenBy

OrderByDescending

ThenByDescending

Take

예제

Northwnd db = new Northwnd(@"c:\northwnd.mdf");
DataLoadOptions dlo = new DataLoadOptions();
dlo.AssociateWith<Customer>(c => c.Orders.Where(p => p.ShippedDate != DateTime.Today));
db.LoadOptions = dlo;
var custOrderQuery =
    from cust in db.Customers
    where cust.City == "London"
    select cust;

foreach (Customer custObj in custOrderQuery)
{
    Console.WriteLine(custObj.CustomerID);
    foreach (Order ord in custObj.Orders)
    {
        Console.WriteLine("\t {0}",ord.OrderDate);
    }
}
Dim db As New Northwnd("c:\northwnd.mdf")

Dim dlo As DataLoadOptions = New DataLoadOptions()
dlo.AssociateWith(Of Customer)(Function(c As Customer) _
        c.Orders.Where(Function(p) p.ShippedDate <> DateTime.Today))
db.LoadOptions = dlo

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

For Each custObj In custOrderQuery
    Console.WriteLine(custObj.CustomerID)
    For Each ord In custObj.Orders
        Console.WriteLine("{0}{1}", vbTab, ord.OrderDate)
    Next

Next

설명

다음 예제에서 내부 루프는 현재 배송되지 않은 루프를 Orders 반복합니다.

적용 대상

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

특정 관계에 대해 검색한 개체를 필터링합니다.

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

형식 매개 변수

T

쿼리 대상 형식입니다.

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

매개 변수

expression
Expression<Func<T,Object>>

특정 일대다 필드 또는 속성에 사용할 쿼리를 식별합니다. 다음 사항에 유의하십시오.

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

유효한 연산자가 아닌 연산자가 식에 나타나면 예외가 throw됩니다. 유효한 연산자는 다음과 같습니다.

Where

OrderBy

ThenBy

OrderByDescending

ThenByDescending

Take

예제

다음 예제에서 내부 루프는 현재 배송되지 않은 루프를 Orders 반복합니다.

Northwnd db = new Northwnd(@"c:\northwnd.mdf");
DataLoadOptions dlo = new DataLoadOptions();
dlo.AssociateWith<Customer>(c => c.Orders.Where(p => p.ShippedDate != DateTime.Today));
db.LoadOptions = dlo;
var custOrderQuery =
    from cust in db.Customers
    where cust.City == "London"
    select cust;

foreach (Customer custObj in custOrderQuery)
{
    Console.WriteLine(custObj.CustomerID);
    foreach (Order ord in custObj.Orders)
    {
        Console.WriteLine("\t {0}",ord.OrderDate);
    }
}
Dim db As New Northwnd("c:\northwnd.mdf")

Dim dlo As DataLoadOptions = New DataLoadOptions()
dlo.AssociateWith(Of Customer)(Function(c As Customer) _
        c.Orders.Where(Function(p) p.ShippedDate <> DateTime.Today))
db.LoadOptions = dlo

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

For Each custObj In custOrderQuery
    Console.WriteLine(custObj.CustomerID)
    For Each ord In custObj.Orders
        Console.WriteLine("{0}{1}", vbTab, ord.OrderDate)
    Next

Next

설명

주기를 방지하는 방법에 대한 자세한 내용은 을 참조하세요 DataLoadOptions.

적용 대상