0
我有重複的數據被插入到數據庫的問題,我在IEnumerable<Location>
傳遞錯誤的參數?C#重複數據問題
它調試應用程序時不會出現任何錯誤。
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();
}
IEnumerable locations = context.Locations.Where(l => l.FacebookID == locationID);似乎爲我做了訣竅,將其從facebook = facebookid更改爲locationID取得了訣竅:) –