简体   繁体   English

嵌套的foreach循环和WCF RIA域服务

[英]nested foreach loops and WCF RIA domain service

I am attempting to load a table of shape coordinates out of a database for plotting on a silverlight bing map, The table structure I am interested in is here http://dl.dropbox.com/u/10440538/ADO.png . 我正在尝试从数据库中加载形状坐标表以在Silverlight bing地图上作图,我感兴趣的表结构在此处http://dl.dropbox.com/u/10440538/ADO.png

Using a wcf ria service I can load the data ok, but I need help with my code to pull out the lowest level data (the coordinates) and separate them into collections. 使用wcf ria服务,可以正常加载数据,但是我需要代码帮助,以提取最低级别的数据(坐标)并将其分离为集合。 The end result should be so that I have a collection of LocationCollections, one LocationCollection for each mapshape in the database. 最终结果应该是这样,以便我有一个LocationCollections集合,数据库中每个mapshape都有一个LocationCollection。

This is my loadoperation callback 这是我的loadoperation回调

    void FarmsLoaded(LoadOperation<Farm> loadOp) {

        LocationCollection lc = new LocationCollection();

        foreach (Farm f in loadOp.Entities) {
            foreach (FarmLocation fl in f.FarmLocations) {
                foreach (MapShape ms in fl.MapShapes) {
                    lc.Clear();
                    foreach (MapPoint mp in ms.MapPoints) {
                        lc.Add(new Location(mp.Latitude, mp.Longitude));
                    }
                    shapeList.Add(lc);   //observablecollection of LocationCollections
                }
            }
        }
    }

shapeList is then bound to a map layer. 然后将shapeList绑定到地图图层。 Unfortunately when I run this only the last mapshape in the db is drawn. 不幸的是,当我运行此命令时,只绘制了数据库中的最后一个mapshape。 I think I misunderstand how the foreach nesting is being traversed so I'd appreciate any effort at enlightenment on correct use of nested foreach in this situation, or any alternate suggestions if foreach is not appropriate (LINQ?) 我想我误解了如何遍历foreach嵌套,因此我很高兴在这种情况下对正确使用嵌套的foreach有所启发,或者在不适合使用foreach的情况下提出任何其他建议(LINQ?)

I think the problem is not related to foreach loop, but instead clearing of lc. 我认为问题与foreach循环无关,而是与lc的清除有关。 Since you are claring lc on for each mapshape, they seem to be deleted from shapelist as well. 由于您为每个mapshape声明了lc,因此它们似乎也从shapelist中删除了。

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

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