带 Prism 的 ADO.NET 数据服务

发布于 2024-08-12 05:19:26 字数 193 浏览 2 评论 0原文

我已经开始将 prism 与 silverlight 3 一起使用,但是,我们正在尝试将其实现为与 ADO.NET DataServices 一起使用。与 Silverlight 一起使用所需的“DataServiceQuery”查询类型需要在查询后触发异步调用。据我所知,这将打破我们的棱镜图案。 有什么想法可以只获取查询数据以在棱镜模式中使用吗?如果我错了,请纠正我!

I've start using prism with silverlight 3, but, we are trying to implement it to work with ADO.NET DataServices. The "DataServiceQuery" query type required to use with Silverlight, requires a Asyncronous call to be fired after the query. This will break ous Prism Pattern by what I can see.
Any ideas to get only the data of the query to use in Prism Pattern? Correct-me anyone if i'm wrong!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

懒猫 2024-08-19 05:19:26

对服务器进行异步调用不会破坏“棱镜模式”。当您的视图需要查询服务器时,其视图模型会触发异步请求并提供回调。调用回调后,它会处理结果并更新它向视图公开的任何属性。这将导致视图根据您在 xaml 中设置的绑定进行更新。

Making an Asynchronous call to your server doesn't break "Prism Pattern". When your view needs to query the server, its viewmodel fires an asynchronous request and provides a callback. Once callback is called, it handles the result and updates whatever properties it exposes to a view. This will result in view updating according to bindings you set up in your xaml.

煮酒 2024-08-19 05:19:26

PL 完全正确。事实上,Prism 鼓励的任何模式都与 ADO.NET 数据服务不兼容。您应该知道一些事情。

这是一个小样本。这有点棘手...完整的事件有时会在 UI 线程之外触发,因此您必须使用调度程序来处理它(至少在 SL2 中您是这样做的):

public class MyViewModel : BaseViewModel
{

     public Customer CustomerResult
     {
         ...
     }

     NorthwindEntities svcContext = null;
     public MyViewModel()
     {
            svcContext =
                new NorthwindEntities(new Uri("Northwind.svc", UriKind.Relative));

            DataServiceQuery<Customers> query =
                svcContext.Customers.Expand("Orders");

            // Begin the query execution.
                query.BeginExecute(WorkComplete, query);

     }



     private void WorkComplete(IAsyncResult result)
     {
          DataServiceQuery<Customers> query =
                    result.AsyncState as DataServiceQuery<Customers>;

          Customers returnedCustomer =
                    query.EndExecute(result).FirstOrDefault();

          //Execute with the dispatcher
          Dispatcher.CurrentDispatcher.BeginInvoke( () =>
          {
               CustomerResult = returnedCustomer;
          });
     }
}

当然这里没有异常处理,但是您得到希望图片。

PL is exactly right. There's really no patterns that Prism encourages that are incompatible with ADO.NET Data Services. There are just a few things you should know.

Here's a small sample. It's a little tricky... the complete event will sometimes fire outside of the UI thread, so you have to handle it with the dispatcher (at least in SL2 you did):

public class MyViewModel : BaseViewModel
{

     public Customer CustomerResult
     {
         ...
     }

     NorthwindEntities svcContext = null;
     public MyViewModel()
     {
            svcContext =
                new NorthwindEntities(new Uri("Northwind.svc", UriKind.Relative));

            DataServiceQuery<Customers> query =
                svcContext.Customers.Expand("Orders");

            // Begin the query execution.
                query.BeginExecute(WorkComplete, query);

     }



     private void WorkComplete(IAsyncResult result)
     {
          DataServiceQuery<Customers> query =
                    result.AsyncState as DataServiceQuery<Customers>;

          Customers returnedCustomer =
                    query.EndExecute(result).FirstOrDefault();

          //Execute with the dispatcher
          Dispatcher.CurrentDispatcher.BeginInvoke( () =>
          {
               CustomerResult = returnedCustomer;
          });
     }
}

Of course there is no exception handling in here, but you get the picture hopefully.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文