RIA Services - Iterate Items in EntityQuery Object

I’m trying to get EF working with SL3, SSL, RIA Services et al. It’s a long road and I know there are issues with any route you decide to take when building a business app in Silverlight 3. In building previous iterations of my little program I used straight WCF services and had issues with host headers when using SSL and the cross domain access file.

RIA Services is definitely easier to work with in terms of the plumbing. It sets up a new handler in the web.config and if you work out your EF model properly, the data access and communications portions go relatively quickly.

The issue I was working through this evening was that I am using the ESRI mapping control and I could not get it to databind the graphics layer to a collection of graphics objects bound to a data context query. The backup plan is to iterate items in the data context query results. Good luck finding a helper post anywhere to write that Linq query! So here is one I finally found in a forum post on the RIA Services list. I lost the URL but here is the relavent code:

// Instance the list of objects we’ll use to
// build the map graphics.
List<MyMapPoint> lst = new List<MyMapPoint>();
// Query that gets the list of points from
// the database.
var queryhist = _MyContext.GetPointsQuery();
// Execute the query.
var qOp = _MyContext.Load(qhist, (pts) =>
{
    foreach (var pt in pts.Entities)
    {
        lst.Add(
                new MyMapPoint(
                pt.PointID,
                pt.PointName, 
                pt.Latitude,
                pt.Longitude
                );
    }
}, null);

I know I could probably serialize my query results directly into my list but I’m just not there yet (read: I don’t know how to do that!).

The points of interest viewer/editor should be up fairly soon at www.muddygps.com. Some time thereafter, the GPS trail routing will also get rolling and then I can start fooling with the race interface. That will be the fun part! Incidentally, the app as it exists right now on the internet is being completely rewritten (again) so it should get a lot faster soon.

Another item up for bids is going to be trying to work out why the cross domain access policy isn’t working right. If I make the entire SilverLight 3 portion of the site SSL it works but as soon as I make it SSL only for the RIA Services data calls, it makes squishing noises. Not going to worry about that one for now because the data access seems to be going relatively quickly for the size of data I’m throwing around.

I’m also building on some of Brad Abrams tutorials for SEO and deep linking. Hopefully that will get my site some traffic. Of course I can’t expect much at the moment since I’ve got a face but no content online.

3 Comments

  • Hi Jim,
    I was looking for something similar which you have explained above,I have tried your sample.
    But get an error at "new MyMapPoint" saying that my code does not have a constructor which take 4 params.
    I tried to add the constructor in the Entity datamodal, and also in domain data service. I run into different errors when i do that.
    Can u please help me?
    where all i need to do the changes?

  • I'm no expert on this so I can't say for sure what your problem is. It's mostly new to me though I understand it conceptually. At any rate, what I have found is that you need to restart IIS, the local Dev Visual Studio instance of IIS and do a clean build in Visual Studio of your project. Then it should recognize any changes you made since last build. Alternatively, you can clear your browser cache. Hope this helps. J

  • Thanks for the reply and the code sample.

    I managed to use your code after lot of effort i managed to find solution to my problem by typecasting pt object to the "MyMapPoint" so i am using your code now.

Comments have been disabled for this content.