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

特定の一対多のフィールドまたは一対多のプロパティで使用するクエリを識別します。 次の点に注意してください。

式の先頭が一対多のリレーションシップを表すフィールドまたはプロパティでない場合は、例外がスローされます。

式に有効な演算子ではない演算子がある場合は、例外がスローされます。 有効な演算子は次のとおりです。

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

クエリする型。

型が割り当てられていない場合、例外がスローされます。

パラメーター

expression
Expression<Func<T,Object>>

特定の一対多のフィールドまたは一対多のプロパティで使用するクエリを識別します。 次の点に注意してください。

式の先頭が一対多のリレーションシップを表すフィールドまたはプロパティでない場合は、例外がスローされます。

式に有効な演算子ではない演算子がある場合は、例外がスローされます。 有効な演算子は次のとおりです。

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

適用対象