Solved

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

Posted on 2010-09-24
3
465 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
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
existenz2 earned 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now