次の方法で共有


方法: Finder メソッドにフィルター記述子を追加する

フィルター記述子を使用すると、モデルのコンシューマーが、メソッドを実行する前にメソッドに値を渡せるようになります。 詳細については、「Business Data Connectivity モデルのデザイン」を参照してください。

たとえば、SharePoint のユーザーが、特定の条件に一致する外部コンテンツ タイプのインスタンスを取得できるようにするには、 Finder メソッドにフィルター記述子を追加します。

Finder メソッドにフィルター記述子を追加するには

  1. [BDC メソッドの詳細] ウィンドウで、Finder メソッドのノードを展開し、[パラメーター] ノードを展開して、入力パラメーターを追加します。 詳細については、「方法 : メソッドにパラメーターを追加する」を参照してください。

  2. [メソッドの詳細] ウィンドウで、そのパラメーターの型記述子を選択します。

  3. [表示] メニューの [プロパティ ウィンドウ] をクリックします。

  4. [プロパティ] ウィンドウで、[型の名前] プロパティを、フィルターに対応するデータ型に設定します。

    たとえば、メソッドから返される販売注文の数を注文日で制限する フィルターをサポートするには、型記述子の [型の名前] プロパティを「System.DateTime」に設定する必要があります。

  5. [メソッドの詳細] ウィンドウで、[フィルター記述子] ノードを展開します。

  6. [フィルター記述子の追加] ボックスの一覧で、[フィルター記述子の作成] をクリックします。

    [フィルター記述子] ノードの下に新しいフィルター記述子が表示されます。

  7. [表示] メニューの [プロパティ ウィンドウ] をクリックします。

  8. [プロパティ] ウィンドウで、[型] プロパティを選択します。

  9. [型] プロパティのドロップダウン リストで、目的のフィルター パターンを選択します。 各フィルター パターンの詳細については、「Types of Filters Supported by the BDC (BDC でサポートされているフィルターの種類)」を参照してください。

    たとえば、Finder メソッドで返される販売注文の数を注文日で制限するフィルターを作成するには、[比較演算] を選択します。 比較フィルターは、Finder メソッドから返されるインスタンスを、特定の条件を満たすもののみに制限します。

  10. [プロパティ] ウィンドウで、[関連付けられた型記述子] プロパティを選択します。

  11. [関連付けられた型記述子] プロパティのドロップダウン リストで、先ほど作成した型記述子を選択します。 これにより、このフィルターが Finder メソッドの入力パラメーターに関連付けられます。

  12. データを返す Finder メソッドにコードを追加します。 入力パラメーターを SELECT クエリの条件として使用できます。

    次の例では、指定した注文日の販売注文を返します。

    注意

    ServerName フィールドの値を、使用するサーバーの名前に置き換えます。

    Public Shared Function ReadList(ByVal OrderDateParam As DateTime) As IEnumerable(Of SalesOrderHeader)
        Const ServerName As String = "MySQLServerName"
        Dim dataContext As AdventureWorksDataContext = _
            New AdventureWorksDataContext("Data Source=" & ServerName & _
                ";Initial Catalog=AdventureWorks;Integrated Security=True")
    
        Dim NoValuePassedIn As DateTime = Convert.ToDateTime("1/1/1900 12:00:00 AM")
        Dim DefaultDateTime As DateTime = Convert.ToDateTime("2001-09-01 00:00:00.000")
    
        ' If the user does not provide a value for the filter.
        If OrderDateParam = NoValuePassedIn Then
            ' Use a default date time value.
            OrderDateParam = DefaultDateTime
        End If
    
        Dim SalesOrderHeader As IEnumerable(Of SalesOrderHeader) = _
            From SalesOrderHeaders In dataContext.SalesOrderHeaders _
            Where SalesOrderHeaders.OrderDate = OrderDateParam _
            Select SalesOrderHeaders
        Return SalesOrderHeader
    End Function
    
    public static IEnumerable<SalesOrderHeader> ReadList(DateTime OrderDateParam)
    {
        const string ServerName = "MySQLServerName";
        AdventureWorksDataContext dataContext = new AdventureWorksDataContext
              ("Data Source=" + ServerName + ";" +
               "Initial Catalog=AdventureWorks;Integrated Security=True");
    
        DateTime NoValuePassedIn = Convert.ToDateTime("1/1/1900 12:00:00 AM");
        DateTime DefaultDateTime = Convert.ToDateTime("2001-09-01 00:00:00.000");
    
        // If the user does not provide a value for the filter.
        if (OrderDateParam == NoValuePassedIn)
        {
            // Use a default date time value.
            OrderDateParam = DefaultDateTime;
        }
    
        IEnumerable<SalesOrderHeader> SalesOrderHeader =
            from salesOrderHeaders in dataContext.SalesOrderHeaders
            where salesOrderHeaders.OrderDate == OrderDateParam
            select salesOrderHeaders;
        return SalesOrderHeader;
    }
    

参照

処理手順

方法: Finder メソッドを追加する

方法: SpecificFinder メソッドを追加する

方法 : メソッドにパラメーターを追加する

その他の技術情報

方法: パラメーターの型記述子を定義する

Business Data Connectivity モデルのデザイン

SharePoint へのビジネス データの統合