0

我需要將來自SQL Server數據庫的一些數據分組,並且由於LightSwitch不支持該開箱即用,我根據Eric使用域服務Erhardt的guideLightSwitch - 使用域名服務將所有請求批量加載到一個請求

但是我的表格包含幾個外鍵,當然我希望在表格中顯示正確的相關數據(就像在指南中做的那樣只會顯示關鍵值)。我解決了這個通過添加這樣對我的新創建實體的關係:

enter image description here

我的域服務類看起來是這樣的:

public class AzureDbTestReportData : DomainService 
    { 
     private CountryLawDataDataObjectContext context; 
     public CountryLawDataDataObjectContext Context 
     { 
      get 
      { 
       if (this.context == null) 
       { 
        EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder(); 
        builder.Metadata = 
         "res://*/CountryLawDataData.csdl|res://*/CountryLawDataData.ssdl|res://*/CountryLawDataData.msl"; 
        builder.Provider = "System.Data.SqlClient"; 
        builder.ProviderConnectionString = 
         WebConfigurationManager.ConnectionStrings["CountryLawDataData"].ConnectionString; 

        this.context = new CountryLawDataDataObjectContext(builder.ConnectionString); 
       } 
       return this.context; 
      } 
     } 

     /// <summary> 
     /// Override the Count method in order for paging to work correctly 
     /// </summary> 
     protected override int Count<T>(IQueryable<T> query) 
     { 
      return query.Count(); 
     } 

     [Query(IsDefault = true)] 
     public IQueryable<RuleEntryTest> GetRuleEntryTest() 
     { 
      return this.Context.RuleEntries 
       .Select(g => 
        new RuleEntryTest() 
        { 
         Id = g.Id, 
         Country = g.Country, 
         BaseField = g.BaseField 
        }); 
     } 
    } 

    public class RuleEntryTest 
    { 
     [Key] 
     public int Id { get; set; } 
     public string Country { get; set; } 
     public int BaseField { get; set; } 
    } 
} 

它的工作原理和所有的,無論是國家名稱並且Basefield會自動加載自動完成框,但它需要很長時間。使用兩列需要5-10秒來加載一個頁面......並且我還有10個列我還沒有實現。

花費這麼長時間的原因是因爲每個相關數據(每個Country和BaseField)都需要一個請求。加載頁面看起來像這樣的小提琴手:

enter image description here

這是不能接受的話,那應該是所有這些電話合併爲一的方式,就像它加載同桌沒有去的時候呢通過域服務。

所以..這是很多解釋,我的問題是:有什麼辦法可以使所有相關數據一次加載或通過任何其他方式提高性能?它不應該花10+秒來加載一個屏幕。

感謝任何幫助或輸入!小號

回答

0

我RIA服務查詢是非常快的,與不使用它們,甚至當我在做的聚集。這可能是因爲您使用RuleEntryTest實體創建的「虛擬關係」(您可以通過表格之間的虛線指出)。

爲什麼在你開始創建RIA實體原來的RuleEntry實體不相關的兩個國家 & 的BaseUnit LightSwitch中?

我還沒有使用Fiddler來查看發生了什麼,但我會嘗試創建「真實」關係而不是「虛擬」關係,&看看是否有助於您的RIA實體的表現。