Solved

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

Posted on 2010-09-24
3
464 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
About delegates in c sharp 3 38
Entity Framework 7 33
Ajax Panel Not Updating When Triggered By Timer 4 46
Help with C#, MVC, razor. 6 23
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

23 Experts available now in Live!

Get 1:1 Help Now