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

1

0

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:

enter image description here

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:

enter image description here

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

Birefringence answered 6/5, 2013 at 6:57 Comment(0)
B
0

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.

Bursarial answered 6/5, 2013 at 16:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.