2010-04-16 101 views
0

我的表添加在EF額外數據列:如何使用ASP.Net MVC 2

[LocationId] 
[Address] 
[ZipCode] 

當我展示位置的列表,我也想展示從給定郵政編碼的距離。
在Asp.Net Web窗體中我有一個存儲過程會返回距離,我會在GridView的ItemDataBound上調用這個SP。

或者,我也會讓我的SP返回位置列表添加另一列([Distance]),我可以在我的GridView中顯示該列。

你會如何使用實體框架和Asp.Net Mvc 2來做到這一點?

回答

0

我?

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);