Home > database >  EF data to new pin location
EF data to new pin location

Time:11-12

I have a SQL Server database with Latitude and Longitude which I have imported through EF to my WPF C# application.

database design

Now in my application I have Bing maps imported where I want to create pushpins from the data I got through my EF query.

private void LoadPins()
{
    var result = (from s in PE.tbl_SafeSpace
                  select new
                         { s.lat, s.@long }).ToList();

    for (int i = 0; i < result.Count; i  )
    {
        Pushpin pin = new Pushpin();
        pin.Location = new Location(result[i]);

        // Adds the pushpin to the map.
        bMaps.Children.Add(pin);
    }    
}  

I know I'm doing something wrong with putting in the data to the location but I'm not sure what.

CodePudding user response:

A suggestion, please comment here if you get errors and I'll glad to update my answer.

private void LoadPins()
{
    List<Location> result = (from s in PE.tbl_SafeSpace
                  select new Location
                         { 
                           Latitude = (double)s.lat,                               
                           Longitude =(double)s.long 
                          }).ToList();

    foreach(Location location in result)
    {
        Pushpin pin = new Pushpin();
        pin.Location = location;

        // Adds the pushpin to the map.
        bMaps.Children.Add(pin);
    }    
} 
  • Related