LightSwitch-使用域服务将所有请求批量加载到一个 [英] LightSwitch - bulk-loading all requests into one using a domain service

查看:120
本文介绍了LightSwitch-使用域服务将所有请求批量加载到一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对SQL Server数据库中的某些数据进行分组,并且由于LightSwitch不支持即用型,因此我根据Eric Erhardt的

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.

但是我的表包含几个外键,我当然希望在表中显示正确的相关数据(就像在指南中所做的那样只会显示键值).我通过将一个Relationship添加到我新创建的Entity中来解决了这个问题,

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:

我的域服务类如下:

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

它可以正常工作,所有国家(地区)名称和基准字段都应按需使用自动完成"框加载,但要花很长时间.有两列需要5-10秒才能加载一页..还有10列我还没有实现.

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.

之所以要花费很长时间,是因为每个相关数据(每个Country和BaseField)都需要一个请求.在Fiddler中加载页面看起来像这样:

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.

所以..对此有很多解释,我的问题是:有什么方法可以一次加载所有相关数据,也可以通过其他方法提高性能吗?加载屏幕应该不需要10秒钟以上的时间.

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.

感谢您的帮助或投入!

推荐答案

即使不进行聚合,与不使用它们相比,我的RIA服务查询也非常快.可能是由于您使用RuleEntryTest实体创建的虚拟关系"(可以通过表之间的虚线表明).

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.

为什么您原始的 RuleEntry 实体与 Country 和&在开始创建RIA实体之前,在LightSwitch中使用 BaseUnit ?

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

我还没有用Fiddler看到正在发生的事情,但是我会尝试创建真实的"关系,而不是虚拟的"关系.看看这是否对您的RIA实体的业绩有所帮助.

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.

这篇关于LightSwitch-使用域服务将所有请求批量加载到一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆