0

I am having problems with duplicate data being inserted in to the database, am I passing a wrong parameter in the IEnumerable<Location>?

It doesn't bring up any errors when I debug the app.

IEnumerable<Location> locations = context.Locations.Where(l => l.FacebookID == facebookID);

if (locations.Count() == 0)
{
    Location newLocation = new Location();

    newLocation.FacebookID = locationID;

    newLocation.Description = locationValue;

    IGeoCoder geoCoder = new GoogleGeoCoder(GoogleAPIKey);
    Address[] addresses = geoCoder.GeoCode(locationValue);

    if (addresses.Length > 0)
    {
        // Let's assume the first one is good enough
        Address address = addresses[0];

         newLocation.Latitude= address.Coordinates.Latitude.ToString();
         newLocation.Longitude = address.Coordinates.Longitude.ToString();
        // Use location.Latitude and location.Longitude

    }

    context.Locations.AddObject(newLocation);
    context.SaveChanges();
}

1 Answer 1

4

I am guessing you did not mean to do this:

newLocation.FacebookID = locationID;

But rather this:

newLocation.FacebookID = facebookID;

Basically you are creating multiple records, with the same facebookId, as you actually used the locationID instead.

1
  • IEnumerable<Location> locations = context.Locations.Where(l => l.FacebookID == locationID); seemed to do the trick for me, changing it from facebook = facebookid to locationID did the trick :) Sep 28, 2011 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.