Tuesday, 10 September 2013

How To Write Distance LINQ query i have Lat, Long in table with varchar type MS SQL Server

How To Write Distance LINQ query i have Lat, Long in table with varchar
type MS SQL Server

How to Write a LINQ query for Nearest Points Calculation,
I have Lat, Lng in table saved as string in MS SQL Database.
Found one solution on skackoverflow the query look like this
var coord = DbGeography.FromText(String.Format("POINT({0} {1})",
latitude.ToString().Replace(",", "."), longitude.ToString().Replace(",",
".")));
var nearest = (from h in db.hotels
where h.location != null
orderby h.location.Distance(coord)
select h).Take(limit);
return nearest;
trying to implement this but the location.distance is not understandable.
can somebody please guide me

No comments:

Post a Comment