Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 5th, 2011, 08:18 AM
Registered User
 
Join Date: May 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default EDMFunction on Page 140

Hi All:
I keep getting this compile error after adding the EdmFunction on pg. 140.

System.Data.Metadata.Edm.EdmFunction' is not an attribute class

I'm using VS 2008. Do I need VS 2010??? I've done some Googling to no avail

Here is my DinnerRepository.cs in case...

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Metadata.Edm;
using System.Data.Objects.DataClasses;

namespace NerdDinner.Models
{
    public class DinnerRepository
    {

        private NerdDinnerEntities entities = new NerdDinnerEntities();

        //
        // Query Methods

        public IQueryable<Dinner> FindAllDinners()
        {
            return entities.Dinners;
        }

        public IQueryable<Dinner> FindUpcomingDinners()
        {
            return from dinner in entities.Dinners
                   where dinner.EventDate > DateTime.Now
                   orderby dinner.EventDate
                   select dinner;
        }
        public Dinner GetDinner(int id)
        {
            return entities.Dinners.FirstOrDefault(d => d.DinnerID == id);
        }

        //
        // Insert/Delete Methods

        public void Add(Dinner dinner)
        {
            entities.AddToDinners(dinner);
        }

        public void Delete(Dinner dinner)
        {
            foreach (var rsvp in dinner.RSVPs)
            {
                entities.DeleteObject(dinner.RSVPs);
            }
            entities.DeleteObject(dinner);
        }
        
        //
        // Persistence 

        public void Save()
        {
            entities.SaveChanges();
        }

        // Helper Methods

        [EdmFunction("NerdDinnerModel.Store", "DistanceBetween")]
        public static double DistanceBetween(double lat1, double long1, double lat2, double long2)
        {
            throw new NotImplementedException("Only call through LINQ expression");
        }
    }
}
Thanks for looking.
 
Old May 5th, 2011, 09:29 AM
Friend of Wrox
 
Join Date: Oct 2010
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Error in the book. Do this:
Code:
	[EdmFunction("NerdDinner.Models.Store", "DistanceBetween")]
 
Old May 5th, 2011, 09:43 AM
Friend of Wrox
 
Join Date: Oct 2010
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Actually, that won't fix your problem. But you'll need to do that anyway.
 
Old May 5th, 2011, 09:44 AM
Friend of Wrox
 
Join Date: Oct 2010
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Check to see if you have .NET Framework 4

http://www.microsoft.com/net/

Last edited by flyinhawaiian; May 5th, 2011 at 09:49 AM..
 
Old May 5th, 2011, 12:54 PM
Registered User
 
Join Date: May 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I believe I do. This directory exists under C:\WINDOWS\Microsoft.NET\Framework

v4.0.30319

Is this the most current version?

Do I need to change anything in my web.config to make sure I am utilizing this?
 
Old May 5th, 2011, 02:32 PM
Friend of Wrox
 
Join Date: Oct 2010
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Delete this line:

using System.Data.Metadata.Edm;
 
Old May 5th, 2011, 03:19 PM
Registered User
 
Join Date: May 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for sticking with this.

After deleting that line, I now have two errors...

Error 1 The type or namespace name 'EdmFunctionAttribute' could not be found (are you missing a using directive or an assembly reference?)

Error 2 The type or namespace name 'EdmFunction' could not be found (are you missing a using directive or an assembly reference?)

As I mentioned before, I did lots of Googling and I ended up figuring out that if I include...

using System.Data.Metadata.Edm;

I am able to get rid of at least one of the errors. That's why it's in there.
 
Old May 5th, 2011, 04:10 PM
Friend of Wrox
 
Join Date: Oct 2010
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

I don't have that line at all. Edm stuff is supposed to be in
using System.Data.Objects.DataClasses;

Perhaps your EntityFramework is out of date.

Download EntityFramework 4
 
Old May 5th, 2011, 04:25 PM
Registered User
 
Join Date: May 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm pretty sure I had EF installed already. I went ahead and re-installed from the link you provided and restarted.

Still have the error.

Are you using VS 2008 or VS2010?
 
Old May 5th, 2011, 04:31 PM
Friend of Wrox
 
Join Date: Oct 2010
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Hmmmm. I'm using VS 2010 Ultimate. Don't think it should make a difference.

[revision] Actually it does make a difference. VS 2008 does not support 4.0 framework.

Last edited by flyinhawaiian; May 6th, 2011 at 11:09 AM.. Reason: mistake





Similar Threads
Thread Thread Starter Forum Replies Last Post
PDF giving first page as blank if page count > 1 using xsl:fo srmxslca XSLT 14 May 5th, 2011 05:01 AM
Page 210:Page object calling a private method from BasePage? aperture8 BOOK: Beginning ASP.NET 4 : in C# and VB 6 August 9th, 2010 07:04 AM
Stuck At Page 140 Yap Dreamweaver (all versions) 2 October 12th, 2004 06:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.