简体   繁体   English

您能否在Silverlight中循环浏览.NET RIA服务调用的结果,就好像它是POCO对象列表一样?

[英]Can you just loop through the results of a .NET RIA services call in silverlight as if it were a list of POCO objects?

    void myButton_Click(object sender, RoutedEventArgs e)
    {
        var oContext = new DomainService1();
        var oResult = oContext.GetPersistMapSet();
        oContext.LoadPersistMapSet();

        foreach (PersistMap oMap in oResult.ToArray<PersistMap>())
            MessageBox.Show(oMap.Data.ToString());
    }

http://screencast.com/t/1bSFIoOU show the issue in action. http://screencast.com/t/1bSFIoOU展示了实际的问题。

foreach (var oMap in oResult.PersistMap) MessageBox.Show(oMap.Data) // does not work foreach(oResult.PersistMap中的var oMap)MessageBox.Show(oMap.Data)//不起作用

The only problem I see with your code sample is that the data isn't loaded into memory at the point where your foreach loop runs. 我在代码示例中看到的唯一问题是,在您的foreach循环运行时,数据没有加载到内存中。 You should hook up to the Loaded event on oContext and run your foreach loop then. 您应该连接到oContext上的Loaded事件,然后运行foreach循环。 This article gives a pretty good overview of RIA Services: 本文对RIA服务进行了很好的概述:

http://msdn.microsoft.com/en-us/magazine/dd695920.aspx http://msdn.microsoft.com/zh-CN/magazine/dd695920.aspx

But the quick answer to your question is "yes." 但是,对您的问题的快速回答是“是”。 ;) ;)

foreach(var item in oContext.PersistMaps) {
    //do stuff
}

oContext.PersistMaps will be an EntityList <PersistMap> which you can iterate over. oContext.PersistMaps将是一个EntityList <PersistMap> ,您可以对其进行迭代。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM