Solved

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

Posted on 2010-09-24
3
458 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
Comment Utility
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
Comment Utility
Without the **ERROR ON THIS LINE**   ofcourse :)
0
 

Author Closing Comment

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

Thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
.NET Error 7 40
Problem to picture file 3 37
Need an intro to -- .Net SQL Authorization Manager 7 47
Get String split 5 31
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 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

12 Experts available now in Live!

Get 1:1 Help Now