Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET MVC 2
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET MVC 2
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
Welcome to the p2p.wrox.com Forums.

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 .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 13th, 2010, 09:41 AM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default '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")]
Note on Page 24, Figure 1-46 shows Model Namespace: NerdDinner.Models.
Reply With Quote
  #2 (permalink)  
Old October 16th, 2010, 07:29 AM
Registered User
 
Join Date: Oct 2010
Location: Zürich
Posts: 8
Thanks: 0
Thanked 1 Time in 1 Post
Default

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;
}
Reply With Quote
  #3 (permalink)  
Old October 29th, 2010, 04:56 PM
Registered User
 
Join Date: Oct 2010
Location: Spokane, WA
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

@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.
Reply With Quote
  #4 (permalink)  
Old October 29th, 2010, 07:05 PM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Yea, I answered my own problem.

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

To this:

Code:
[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.

Last edited by flyinhawaiian; October 29th, 2010 at 07:11 PM.
Reply With Quote
The Following User Says Thank You to flyinhawaiian For This Useful Post:
ethan.kapua (October 29th, 2010)
  #5 (permalink)  
Old October 29th, 2010, 08:03 PM
Registered User
 
Join Date: Oct 2010
Location: Spokane, WA
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

@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!
Reply With Quote
  #6 (permalink)  
Old October 29th, 2010, 08:19 PM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

@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.
Reply With Quote
  #7 (permalink)  
Old October 17th, 2011, 04:54 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #8 (permalink)  
Old June 18th, 2012, 11:51 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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;
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linq Problem sridharnetha C# 2005 1 December 29th, 2009 06:31 AM
LINQ vaibhavgoe LINQ 4 December 21st, 2009 02:49 PM
LINQ to SQL bakm04 BOOK: Professional C# 2008 ISBN: 978-0-470-19137-8 0 August 17th, 2009 04:07 PM
LINQ query \ LAMBDA expression - complex requirement sumitshah4u .NET Framework 3.5 0 March 16th, 2009 04:36 AM
Message> in query expression <expression>. (Error ybg1 Access 5 July 15th, 2007 05:42 AM



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


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