This is the forum to discuss the Wrox book Professional ASP.NET MVC 2 by Jon Galloway, Scott Hanselman, Phil Haack, Scott Guthrie, Rob Conery; ISBN: Professional ASP.NET MVC 2
You are currently viewing the BOOK: Professional ASP.NET MVC 2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
'Double DistanceBetween..' cannot be translated into a LINQ to Expression
Page 140
I got a runtime error when search is pressed. Doesn't appear that anyone else has this problem or maybe just unreported.
Error:
base {System.SystemException} = {"The specified method 'Double DistanceBetween(Double, Double, Double, Double)' on the type
'NerdDinner.Models.DinnerRepository' cannot be translated into a LINQ to Entities store expression."}
Something else that needs sorted on the FindByLocation() method is the lambda expression.
Code:
var dinners = from dinner in FindUpcomingDinners()
join i in NearestDinners(latitude, longitude)
on dinner.DinnerID equals i.DinnerID
select dinner;
Will highlight an error on
Code:
NearestDinners(latitude, longitude)
unless you include the following method (in the downloaded final solution this method is included immediately below the public static double DistanceBetween() stub function in DinnerRepository.cs)
Code:
public IQueryable<Dinner> NearestDinners(double latitude, double longitude)
{
return from d in entities.Dinners
where DistanceBetween(latitude, longitude, d.Latitude, d.Longitude) < 100
select d;
}
Notice the period between NerdDinner and Models. I think I may have done some other adjustments found in the forum (search for "NearestDinners"). Continue to post messages in the forums if you still have problems. I'll try to help you get through.
Last edited by flyinhawaiian; October 29th, 2010 at 07:11 PM.
The Following User Says Thank You to flyinhawaiian For This Useful Post:
Thanks for the tip! I needed to adjust the Json Object to return an EventDate to get it to fully work, but now it does! So what is going on here? We are referencing where the NerdDinner.edmx is through NerDinner.Models and then the added .Store at the end references where the DistanceBetween function is?
Thanks again. I may ask you for more help as I go along!
@ethan
Yes, it's called the namespace. The book fumbled on this (and many other things). You'll see namespaces used everywhere classes are defined. Often you can have more than one class with the same name. They can coexist because each can be in their own namespace. Namespaces help distinguish one class from another. Just like you can have two peopled named Kimo. One that lives on Maui and the other on Oahu. I'm monitoring all the threads. So, I'll see whatever is posted in the forum for ASP.net MVC.
you may have to change the datatype of the properties of Latitude and Longtitude in NerdDinner.Design.CS
public global::System.Double Latitude{....}
private global::System.Double _Latitude;
public global::System.Double Longitude{....}
private global::System.Double _Longitude;