1

WCF Data Services で汎用データ ブラウザーのプロトタイプを作成しています。

ユーザーは TreeView からエンティティを選択できるため、クエリの結果の種類をハードコードすることはできず、クエリ (URI または LINQ) を動的にコーディングする必要があります。

異なるデータ サービス間で結合を提供するために、各データ サービスからの結果をクライアントにロードして、それらを動的に結合しようとしています。

Dim q1 As IQueryable = ctx.Execute(Of Object)(New Uri("Service1.svc/Customers")).ToList.AsQueryable

Dim q2 As IQueryable = ctx.Execute(Of Object)(New Uri("Service2.svc/Orders")).ToList.AsQueryable

Dim j = q1.JoinDynamic("q1", q2, "q2", "q1.CustomerID", "q2.CustomerID", "New (q1.CustomerID as q1id, q1.CompanyName as CompanyName)")

動的 Join を使用する際に問題が発生しました。参照:リンクテキスト

  1. ctx.Execute は、型が実行時まで不明な場合に結果を照会する正しい方法ですか?

  2. Data Services を介して動的結合を実装する方法について、誰かがより良いアイデアを持っていますか?

4

1 に答える 1

0

回避策として、メモリ内アセンブリを介して結合コードを動的に作成しました。これはうまくいくようです。デバッガーで結合結果を確認できます。結果を DataGrid にバインドする方法がわからないだけです。

        Dim codeDomProvider = New VBCodeProvider
    Dim cp As New Compiler.CompilerParameters
    cp.GenerateExecutable = False
    cp.GenerateInMemory = True
    cp.CompilerOptions = "/optionexplicit- /optionstrict-"
    cp.ReferencedAssemblies.Add(IO.Path.ChangeExtension(My.Application.Info.AssemblyName, "exe"))
    cp.ReferencedAssemblies.Add("System.dll")
    cp.ReferencedAssemblies.Add("System.Core.dll")
    cp.ReferencedAssemblies.Add("System.Data.Services.Client.dll")

    Dim sb = New Text.StringBuilder()
    sb.Append("Imports System" & vbCrLf)
    sb.Append("Imports System.Linq" & vbCrLf)
    sb.Append("Imports " & My.Application.Info.AssemblyName & vbCrLf)
    sb.Append("Public Class JoinHelper" & vbCrLf)
    sb.Append("Public Shared Function GetData() As Object" & vbCrLf)
    sb.Append("  Dim ctx1 As New NorthwindDataService.NorthwindEntities(New Uri(""http://localhost:3631/NorthwindDataService.svc/""))" & vbCrLf)
    sb.Append("  Dim ctx2 As New SalesDataService.SalesEntities(New Uri(""http://localhost:4354/SalesDataService.svc""))" & vbCrLf)
    sb.Append("  Dim q1 as System.Data.Services.Client.QueryOperationResponse (of NorthwindDataService.Customers) = ctx1.Execute(Of NorthwindDataService.Customers)(New Uri(""Customers"", UriKind.Relative))" & vbCrLf)
    sb.Append("  Dim q2 as System.Data.Services.Client.QueryOperationResponse (of SalesDataService.CustomerSize) = ctx2.Execute(Of SalesDataService.CustomerSize)(New Uri(""CustomerSize"", UriKind.Relative))" & vbCrLf)
    sb.Append("  Dim j = From c In q1 Join s In q2 On c.CustomerID Equals s.CustomerID Select New With {c.CompanyName, s.Size}" & vbCrLf)
    'sb.Append("  return j.tostring" & vbCrLf)
    sb.Append("  return j" & vbCrLf)
    'sb.Append("  r = j.ToList" & vbCrLf)
    'sb.Append("  return r" & vbCrLf)
    sb.Append("End Function" & vbCrLf)
    sb.Append("End Class" & vbCrLf)
    sb.Append(vbCrLf)
    Dim code = sb.ToString
    Dim compilerResults = codeDomProvider.CompileAssemblyFromSource(cp, code)
    If compilerResults.Errors.HasErrors Then
        Throw New ApplicationException(compilerResults.Errors.Item(0).ToString)
    End If
    Dim o = compilerResults.CompiledAssembly.CreateInstance("JoinHelper")
    Dim t = o.GetType
    Dim j = t.InvokeMember("GetData", Reflection.BindingFlags.InvokeMethod, Nothing, o, Nothing)
    DataGrid1.ItemsSource = j
于 2010-02-12T17:26:06.647 に答える