How to add additional data column in EF using ASP.Net MVC 2
My Table:
[LocationId]
[Address]
[ZipCode]
When I show a list of Location's, I also want to show the distance from a given zip code.开发者_高级运维
In Asp.Net Web Forms I had a stored procedure that would return the distance and I would call this SP on ItemDataBound on my GridView.Or, I also would have my SP that is returning the Location list add another column ([Distance]) which I could display in my GridView.
How would you do this using Entity Framework and Asp.Net Mvc 2?
Me?
LocationPresentation model = Repository.Locations
.Where(l => l.Id == someId)
.AsEnumerable()
.Select(l => new LocationPresentation
{
Id = l.Id,
Address = l.Address,
ZipCode = l.ZipCode,
Distance = DistanceLib.ComputeDistance(someZIP, l.ZipCode)
});
return View(model);
精彩评论