Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3339688
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:31:17+00:00 2026-05-18T00:31:17+00:00

Alright folks, I am a newcomer to Data Services and LINQ in desperate need

  • 0

Alright folks, I am a newcomer to Data Services and LINQ in desperate need of some guidance. In just a few days I have encountered numerous unexpected obstacles and I’m stuck on one now. I’m hoping these are just typical frustrations of learning a new tool.

I have a WCF Data Service for serving up data from a Sql Server database table of Gps coordinates. In particular I have a service operation method that allows you to specify a decimal precision and latitude/longitude range to produce a more general representation of the data.

In a web browser it appears to work just as expected. However when I try to call the operation from my client application, the list returned to the client differs from the list generated by the service.

I will use pieces of my code to explain the details:

Data Service Operation:

    // This is my service operation that I need to call from my client app (see below). 
    // It should return an IEnumerable<Gps> (Gps is one of my Entity Model 
    // types) list of distinct GPS rounded to the number of decimal positions 
    // specified and within the range specified.
    [WebGet]
    public IEnumerable<Gps> GetGpsView(int decimalPlaces, decimal minLatitude, decimal minLongitude, decimal maxLatitude, decimal maxLongitude)
    {
        // I must first return a list of anonymous-type objects
        // because LINQ does not seem to allow me to construct my
        // Gps object within the query (one of those other issues
        // I had to tip-toe around).
        var list = (from g in this.CurrentDataSource.Gps
                    where g.Latitude >= minLatitude &&
                             g.Latitude <= maxLatitude &&
                             g.Longitude >= minLongitude &&
                             g.Longitude <= maxLongitude
                    select new
                    {
                        Id = 0,
                        Latitude = Math.Round(g.Latitude, decimalPlaces),
                        Longitude = Math.Round(g.Longitude, decimalPlaces)
                    }).Distinct().ToList();

        // Now that I have my results, I need to convert the items in the
        // list to my Gps entity object.
        IEnumerable<Gps> gpsList = list.ConvertAll<Gps>(item => new Gps
                            {
                                Id = item.Id,
                                Latitude = item.Latitude,
                                Longitude = item.Longitude
                            });

        return gpsList;
    }

If I debug the above method (running it on Visual Studio’s virtual server) when called from my client app, gpsList appears to contain the proper data just before returning to the client. Using my test parameters, I get a list of 200 distinct Gps objects whose values are rounded to the decimal places I specify.

However, once the results are returned to the calling method in my client app, I have a list of 200 Gps objects, but they are all the SAME value. To be specific, the duplicated value is the LAST value in my expected result set. I confirmed this by calling this operation in a web browser and viewing the results.

Client Method:

// Partial class extension of code auto-generated by service reference.
public partial class HsiSideBySideEntities
{
    public List<Gps> GetGpsView(int decimalPlaces, decimal minLatitude, decimal minLongitude, decimal maxLatitude, decimal maxLongitude)
    {
        this.IgnoreMissingProperties = true;

        // Format my relative URI string.
        string uri = string.Format("/GetGpsView?decimalPlaces={0}&minLatitude={1}M&minLongitude={2}M&maxLatitude={3}M&maxLongitude={4}M", decimalPlaces, minLatitude, minLongitude, maxLatitude, maxLongitude);

        // If I debug both client and service at the same time, when I step over this
        // line, it does reach my data service - and as I mentioned above, on the
        // service end it appears to generate the correct results.
        List<Gps> gpsList = this.Execute<Gps>(new Uri(uri, UriKind.Relative)).ToList();

        // However, the results are returned to the client code, my list contains
        // duplicates of the last expected record.
        return gpsList;
    }
}

I tried removing the “ToList()” portion of the “Execute()” line, but when I try to view the result set in the debugger, it shows an exception that reads, “Only a single enumeration is supported by this IEnumerable.”

As far as I can tell, my client code is first suspect. After all, every other test shows that my data service operation is producing the desired results.

Do I need to do something different to obtain the IEnumerable list of objects from the data service?

I understand there is a CreateQuery() option, but I’ve read that Execute() is the more appropriate route for this scenario.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:31:17+00:00Added an answer on May 18, 2026 at 12:31 am

    It’s probably because of this:

    select new
    {
        Id = 0,
        Latitude = Math.Round(g.Latitude, decimalPlaces),
        Longitude = Math.Round(g.Longitude, decimalPlaces)
    }
    

    I assume that the Id property of the Gps entity is your primary key. In your example you are setting the Id of each returned Gps to zero. In the WCF Data Services client library, entities with the same primary key are treated as the same instance both for change tracking reasons and so that object graphs behave as you would expect in an object-oriented, reference-tracked environment such as .NET.

    If for some reason you can’t give the Gps entities a unique Id, consider using a Guid for the primary key.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I have some data that I need to assign an int type identifier
Alright, I have a script that takes a few arguments, runs data, and then
Alright folks, my brain is fried. I'm trying to fix up some EMLs with
Alright. So I have a very large amount of binary data (let's say, 10GB)
Alright, I have some code that will find a <code></code> tag set and clean
Alright so i need to open a .txt file that will be created in
Alright so I have no idea how to even begin doing this But basically
Alright I created some custom classes for my project sourced from this tutorial ,
Alright so I have been looking around (on SO and Google) to see if
Alright I have been looking for this for a while now, and didn't really

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.