![]() |
'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."} Traced the problem to Code Snippet 1-99.txt DinnerRepository.cs Change this: [EdmFunction("NerdDinnerModel.Store", "DistanceBetween")] To this: Code:
[EdmFunction("NerdDinner.Models.Store", "DistanceBetween")] |
Something else that needs sorted on the FindByLocation() method is the lambda expression.
Code:
var dinners = from dinner in FindUpcomingDinners()Code:
NearestDinners(latitude, longitude)Code:
public IQueryable<Dinner> NearestDinners(double latitude, double longitude) |
@flyinhawaiian
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. |
Yea, I answered my own problem.
Change this: [EdmFunction("NerdDinnerModel.Store", "DistanceBetween")] To this: Code:
[EdmFunction("NerdDinner.Models.Store", "DistanceBetween")] |
@flyinHawaiian
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. |
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" /> </Function> All parameters and a return type should be float |
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; |
| All times are GMT -4. The time now is 12:26 PM. |
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.