Database Reference
In-Depth Information
static void RunExample()
{
using (var context = new EFRecipesEntities())
{
var c1 = new WebCustomer { Name = "Alex Stevens", Zip = "76039" };
var c2 = new WebCustomer { Name = "Janis Jones", Zip = "76040" };
var c3 = new WebCustomer { Name = "Cathy Robins", Zip = "76111" };
context.Zips.Add(new Zip
{
Latitude = 32.834298M,
Longitude = -32.834298M,
ZipCode = "76039"
});
context.Zips.Add(new Zip
{
Latitude = 32.835298M,
Longitude = -32.834798M,
ZipCode = "76040"
});
context.Zips.Add(new Zip
{
Latitude = 33.834298M,
Longitude = -31.834298M,
ZipCode = "76111"
});
context.WebCustomers.Add(c1);
context.WebCustomers.Add(c2);
context.WebCustomers.Add(c3);
context.SaveChanges();
}
using (var context = new EFRecipesEntities())
{
string esql = @"select value c
from EFRecipesEntities.WebCustomers as c
join
(SELECT z.ZipCode,
3958.75 * (SqlServer.Atan(SqlServer.Sqrt(1 -
SqlServer.power(((SqlServer.Sin(t2.Latitude/57.2958M) *
SqlServer.Sin(z.Latitude/57.2958M)) +
(SqlServer.Cos(t2.Latitude/57.2958M) *
SqlServer.Cos(z.Latitude/57.2958M) *
SqlServer.Cos((z.Longitude/57.2958M) -
(t2.Longitude/57.2958M)))), 2)) /(
((SqlServer.Sin(t2.Latitude/57.2958M) *
SqlServer.Sin(z.Latitude/57.2958M)) +
(SqlServer.Cos(t2.Latitude/57.2958M) *
SqlServer.Cos(z.Latitude/57.2958M) *
SqlServer.Cos((z.Longitude/57.2958M) -
(t2.Longitude/57.2958M))))))
) as DistanceInMiles
Search WWH ::




Custom Search