?
Solved

ASP.NET MVC Error: must declare a body because it is not marked abstract

Posted on 2010-09-24
3
Medium Priority
?
475 Views
Last Modified: 2012-05-10
Hi All,

I'm going through a book to help me learn ASP.NET MVC. I've got to a point where I seem to be getting errors, but I can't figure out why.

I have two classes, an IProductRepository and ProductRespository.

IProductRepository is this...

namespace ToyStore.Models
{
    public class IProductRepository
    {
        public IEnumerable<Product> List();  **ERROR ON THIS LINE**
        Product Get(int id);  **ERROR ON THIS LINE**
        void Create(Product productToCreate);  **ERROR ON THIS LINE**
        void Edit(Product productToEdit);  **ERROR ON THIS LINE**
        void Delete(Product productToDelete);  **ERROR ON THIS LINE**
    }
}

and ProductRepository...

namespace ToyStore.Models
{
    public class ProductRepository : IProductRepository
    {
        private ProductsDBEntities _entities = new ProductsDBEntities();

        #region IProductRepository Members
        public IEnumerable<Product> List()
        {
            return _entities.ProductSet.ToList();
        }

        public Product Get(int Id)
        {
            return (from p in _entities.ProductSet where p.Id == Id select p).FirstOrDefault();
        }

        public void Create(Product productToCreate)
        {
            _entities.AddToProductSet(productToCreate);
            _entities.SaveChanges();
        }

        public void Edit(Product productToEdit)
        {
            var originalProduct = Get(productToEdit.Id);
            _entities.ApplyPropertyChanges(originalProduct.EntityKey.EntitySetName,productToEdit);
            _entities.SaveChanges();
        }

        public void Delete(Product productToDelete)
        {
            var originalProduct = Get(productToDelete.Id);
            _entities.DeleteObject(originalProduct);
            _entities.SaveChanges();
        }

        #endregion
    }
}


Does anyone have any ideas? I had a look around google, and a few results said to make sure that the project framework is 3.5, I've checked this, and it is.
0
Comment
Question by:SheppardDigital
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
existenz2 earned 2000 total points
ID: 33753747
It's quite easy. You have defined a class where it should be an interface;

namespace ToyStore.Models
{
    public class IProductRepository
    {
        public IEnumerable<Product> List();  **ERROR ON THIS LINE**
        Product Get(int id);  **ERROR ON THIS LINE**
        void Create(Product productToCreate);  **ERROR ON THIS LINE**
        void Edit(Product productToEdit);  **ERROR ON THIS LINE**
        void Delete(Product productToDelete);  **ERROR ON THIS LINE**
    }
}


should be:

namespace ToyStore.Models
{
    public interface IProductRepository
    {
        public IEnumerable<Product> List();  **ERROR ON THIS LINE**
        Product Get(int id);  **ERROR ON THIS LINE**
        void Create(Product productToCreate);  **ERROR ON THIS LINE**
        void Edit(Product productToEdit);  **ERROR ON THIS LINE**
        void Delete(Product productToDelete);  **ERROR ON THIS LINE**
    }
}

Open in new window

0
 
LVL 14

Expert Comment

by:existenz2
ID: 33753749
Without the **ERROR ON THIS LINE**   ofcourse :)
0
 

Author Closing Comment

by:SheppardDigital
ID: 33753782
Sometimes it takes someone else to take a look and pinpoint your errors :)

Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question