设置Domain Service传输给datagrid的记录条数的方法等。。

来源:互联网 发布:淘宝管控记录什么意思 编辑:程序博客网 时间:2024/06/07 08:19

闲来无事瞎写。。。

首先是在ASP.NET页面中使用Domain  Service

目前基本上就是官网的例子,没多少去讨论这个,大家最多是在Silverlight项目中使用。毕竟是个新的数据传输方式,它完全可以在.net项目中为你服务。如果你不了解WCF RIA  Service的机制,可以看下面这个图:

 

最终就是把Domain Service转化为WCF的样式来传输数据。

你现在如果是给一个Gridview选择一个数据源,现在也可以使用Domain Service

 

同理的创建一个ADO.NET Data Model,然后以此为context创建domain Service

 

然后创建一个aspx页面。拖上去一个DomainDataSource。选择刚才创建好的Domain Service来作为Data Source 然后拖上去一个GridView,选择上面创建好的Domain Service作为数据源。使用Domain Service很重要的一点就是我们不再不需要写那么多的Validation信息了。比如我这里在Domain Service已经要求Color不能为空,

[Required(AllowEmptyStrings=false,

                ErrorMessage="Color is required")]

            public string Color { get; set; }

 

然后在aspx页面上添加一个Domain Validator,运行下看看:

Update信息时Color为空,警告信息会自动显示:

 

 

有兴趣自己去参考下:http://go.microsoft.com/fwlink/?LinkId=185200

 

2.如何自定义Silverlight的验证错误信息格式。

默认显示的都是红色的边框和红色的字,如下图:

 

如何自定义警告信息的格式?

先看看我的最后效果:

 

首先我们需要添加Resourcesxaml页面中:

 

这就是个自定义的验证信息模板。下面是我点击Button时添加这个警告信息模板到textbox后:

 

                var border = ((Border)VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(myTextBox, 0), 3));

                var tooltip = border.GetValue(ToolTipService.ToolTipProperty) as ToolTip;

               

                tooltip.DataContext = "Text can not be empty";

 

                tooltip.Template = this.Resources["ValidationToolTipTemplate"] as ControlTemplate;

 

                if (!myTextBox.Focus())

                    VisualStateManager.GoToState(myTextBox, "InvalidUnfocused", true);

                else

 

                    VisualStateManager.GoToState(myTextBox, "InvalidFocused", true);

 

3.如何防止WCF RIA Service传输过多的数据到DataGrid中。

数据太多确实没啥用,毕竟我们不需要一下子展现这么多数据出来。

首先是在Domain Service方面使用ResultLimit属性。

   [Query(ResultLimit = 1000)]

        public IQueryable<Customer> GetCustomers()

        {

            return this.ObjectContext.Customers;

        }

然后就是在使用Domain Servicexaml页面中设置loadsize:

 

最后一个是使用在查询结果时使用Take方法:

      EntityQuery<Customer> query = _customerDomainContext.GetCustomerSetQuery()

                                                       .OrderBy(customer => customer.CompanyName)

                                                       .Skip(0)

                                                       .Take(21);

上面的结果时查询21条记录。

原创粉丝点击