LightSwitch - bulk-loading all requests into one using a domain service

别等时光非礼了梦想. 提交于 2019-12-23 04:23:57

问题


I need to group some data from a SQL Server database and since LightSwitch doesn't support that out-of-the-box I use a Domain Service according to Eric Erhardt's guide.

However my table contains several foreign keys and of course I want the correct related data to be shown in the table (just doing like in the guide will only make the key values show). I solved this by adding a Relationship to my newly created Entity like this:

And my Domain Service class looks like this:

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; }
    }
}

It works and all that, both the Country name and the Basefield loads with Autocomplete-boxes as it should, but it takes VERY long time. With two columns it takes 5-10 seconds to load one page.. and I have 10 more columns I haven't implemented yet.

The reason it takes so long time is because each related data (each Country and BaseField) requires one request. Loading a page looks like this in Fiddler:

This isn't acceptable at all, it should be a way of combining all those calls into one, just as it does when loading the same table without going through the Domain Service.

So.. that was a lot explaining, my question is: Is there any way I can make all related data load at once or improve the performance by any other way? It should not take 10+ seconds to load a screen.

Thanks for any help or input!s


回答1:


My RIA Service queries are extremely fast, compared to not using them, even when I'm doing aggregation. It might be the fact that you're using "virtual relationships" (which you can tell by the dotted lines between the tables), that you've created using your RuleEntryTest entity.

Why is your original RuleEntry entity not related to both Country & BaseUnit in LightSwitch BEFORE you start creating your RIA entity?

I haven't used Fiddler to see what's happening, but I'd try creating "real" relationships, instead of "virtual" ones, & see if that helps your RIA entity's performance.



来源:https://stackoverflow.com/questions/16393563/lightswitch-bulk-loading-all-requests-into-one-using-a-domain-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!