2012-12-05 106 views
0

我要查詢,我需要兩個合併成一個結果,我已經嘗試與聯盟的毗連,但沒有成功:如何合併兩個EF查詢?

 Dim PayPalPurchases = (From p In ctx.PayPalAPI Where p.Users.Email = userEmail Select 
          KeyPay = p.pay_key, 
          PurchaseDate = p.payment_request_date, 
          Result = p.status, 
          item_sku = p.memo, 
          price = p.transaction_amount).ToList 

     Dim licenze = (From lic In ctx.Licenses Where lic.Users.Email = userEmail 
          Select KeyPay = lic.Note, 
          PurchaseDate = lic.Date, 
          Result = "Free", 
          item_sku = lic.Sku, 
          price = 0) 

回答

1

創建每個查詢結果存儲在一個類:

Public Class ResultData 

    Public KeyPay As String 
    Public PurchaseDate As String 
    Public Result As String 
    Public item_sku As String 
    Public price As String 

End Class 

然後創建一個列表有兩個結果

Dim PayPalPurchases = (From p In ctx.PayPalAPI 
         Where p.Users.Email = userEmail 
         Select New ResultData With 
         { 
          .KeyPay = p.pay_key, 
          .PurchaseDate = p.payment_request_date, 
          .Result = p.status, 
          .item_sku = p.memo, 
          .price = p.transaction_amount 
         }).ToList 

Dim licenze = (From lic In ctx.Licenses 
       Where lic.Users.Email = userEmail 
       Select New ResultData With 
       { 
        .KeyPay = lic.Note, 
        .PurchaseDate = lic.Date, 
        .Result = "Free", 
        .item_sku = lic.Sku, 
        .price = 0 
       }).toList 

Dim combinedList As List(Of ResultData) 

combinedList.AddRange(PayPalPurchases) 
combinedList.AddRange(licenze)