public static IEnumerable <GeoLatLonAlt> GetAltitudeForCoords(double lat, double lng, double distance) { distance = distance / 1000; using (var db = new BotContext()) { return (db.MapzenAlt.Where( x => 12742 * SqlCeFunctions.Asin( SqlCeFunctions.SquareRoot(SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) + SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * lat) * SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * x.Lat) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2))) < distance).OrderBy(x => 12742 * SqlCeFunctions.Asin( SqlCeFunctions.SquareRoot(SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) + SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * lat) * SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * x.Lat) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2)))).ToList()); } }
public static bool ElevationDataExists(double lat, double lng, double distance) { distance = distance / 1000; using (var db = new BotContext()) { var res = false; try { res = db.MapzenAlt.Any( x => 12742 * SqlCeFunctions.Asin( SqlCeFunctions.SquareRoot( SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) + SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * lat) * SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * x.Lat) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2))) < distance); } catch (Exception) { //ignore } return(res); } }
public void SqlCeFunction_passing_function_as_argument_to_another_works() { using (var context = GetArubaCeContext()) { var query = context.AllTypes.Select(a => SqlCeFunctions.Asin(SqlCeFunctions.Acos(a.c10_float))); Assert.Contains("ASIN", query.ToString().ToUpperInvariant()); Assert.Contains("ACOS", query.ToString().ToUpperInvariant()); } }
public void SqlCeFunctions_scalar_function_translated_properly_to_sql_function() { using (var context = GetArubaCeContext()) { var query1 = context.AllTypes.Select(a => SqlCeFunctions.Acos(a.c7_decimal_28_4)); var query2 = context.AllTypes.Select(a => SqlCeFunctions.Acos(a.c10_float)); Assert.Contains("ACOS", query1.ToString().ToUpperInvariant()); Assert.Contains("ACOS", query2.ToString().ToUpperInvariant()); } }
public static IEnumerable <PokemonSeen> GetPokemonSeenForCoords(double lat, double lng, double distance) { distance = distance / 1000; using (var db = new BotContext()) { return (db.PokemonSeen.Where( x => 12742 * SqlCeFunctions.Asin( SqlCeFunctions.SquareRoot(SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Latitude - lat) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Latitude - lat) / 2) + SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * lat) * SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * x.Latitude) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Longitude - lng) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Longitude - lng) / 2))) < distance).ToList()); } }
public ActionResult Index( string date = null, string slug = null) { DateTime selectedDate; if (string.IsNullOrEmpty(date) || !DateTime.TryParse(date, out selectedDate)) { selectedDate = DateTime.Today; } ViewBag.SelectedDate = selectedDate; ViewBag.Category = string.IsNullOrEmpty(slug) ? null : Db.EventCategories.FirstOrDefault(x => x.Slug.Equals(slug, StringComparison.OrdinalIgnoreCase)); return(View(Db.Events.Include(x => x.Category).Where(x => (slug == null || x.Category.Slug.Equals(slug, StringComparison.OrdinalIgnoreCase)) && x.IsActive && SqlCeFunctions.DateDiff("DAY", x.EventDate, selectedDate) == 0).OrderBy(x => x.EventDate).ToList())); }