p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Professional ASP.NET MVC 2 (http://p2p.wrox.com/book-professional-asp-net-mvc-2-588/)
-   -   'Double DistanceBetween..' cannot be translated into a LINQ to Expression (http://p2p.wrox.com/book-professional-asp-net-mvc-2/81232-double-distancebetween-cannot-translated-into-linq-expression.html)

flyinhawaiian October 13th, 2010 09:41 AM

'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.

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."}

Traced the problem to Code Snippet 1-99.txt

Change this:
[EdmFunction("NerdDinnerModel.Store", "DistanceBetween")]

To this:

[EdmFunction("NerdDinner.Models.Store", "DistanceBetween")]
Note on Page 24, Figure 1-46 shows Model Namespace: NerdDinner.Models.

ajameson October 16th, 2010 07:29 AM

Something else that needs sorted on the FindByLocation() method is the lambda expression.


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


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)


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;

ethan.kapua October 29th, 2010 04:56 PM


Did you ever find an answer to your problem? I am having the same issue as well and I can't believe nobody else has posted this problem.

flyinhawaiian October 29th, 2010 07:05 PM

Yea, I answered my own problem.

Change this:
[EdmFunction("NerdDinnerModel.Store", "DistanceBetween")]

To this:


[EdmFunction("NerdDinner.Models.Store", "DistanceBetween")]
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.

ethan.kapua October 29th, 2010 08:03 PM


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!

flyinhawaiian October 29th, 2010 08:19 PM

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.

alvicstep October 17th, 2011 04:54 PM

In my case I had to update DistanceBetween function in the edmx file:

<Function Name="DistanceBetween" ReturnType="float" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
<Parameter Name="Lat1" Type="float" Mode="In" />
<Parameter Name="Long1" Type="float" Mode="In" />
<Parameter Name="Lat2" Type="float" Mode="In" />
<Parameter Name="Long2" Type="float" Mode="In" />

All parameters and a return type should be float

mengxiao88 June 18th, 2012 11:51 PM

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;

chennaiwebdesign November 6th, 2014 05:26 AM

Hi guys,I am beginning learner of ASP.Net.This post is more useful to us.Thanks for your valuable information[:)][:)]

Leading Web Designing Services Company in Chennai - WEB DESIGN CHENNAI

All times are GMT -4. The time now is 01:16 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.