创建一个有错误的存储库?

时间:2012-04-12 15:29:42

标签: asp.net-mvc visual-studio-2010 asp.net-mvc-3 html5 class

我正在尝试使用以下教程http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application创建一个存储库我收到了这两个错误。

找不到类型或命名空间名称'IShowRepository'(您是否缺少using指令或程序集引用?)

无法找到元数据文件'C:\ Users \ Ben \ Documents \ Visual Studio 2010 \ Projects \ StudentTheatreGroupWebsite \ StudentTheatreGroupWebsite \ bin \ StudentTheatreGroupWebsite.dll'StudentTheatreGroupWebsite.Tests

非常感谢任何帮助......

using System;
using System.Collections.Generic
using System.Data;
using System.Linq;
using StudentTheatreGroupWebsite.Models;

namespace StudentTheatreGroupWebsite.DAL
{
    public class ShowRepository : IShowRepository , IDisposable
    {
        private StudentTheatreContext context;

        public ShowRepository(StudentTheatreContext context)
        {
            this.context = context;
        }

        public IEnumerable<Show> GetShows()
        {
            return context.Shows.ToList();
        }

        public Show GetShowByID(int id)
        {
            return context.Shows.Find(id);
        }

        public void InsertShow(Show show)
        {
            context.Shows.Add(show);
        }

        public void DeleteShow(int ShowID)
        {
            Show show = context.Shows.Find(ShowID);
            context.Shows.Remove(Shows);
        }

        public void UpdateShow(Show show)
        {
            context.Entry(show).State = EntityState.Modified;
        }

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

        private bool disposed = false;

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    context.Dispose();
                }
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

我在编辑前复制了您的代码:

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using StudentTheatreGroupWebsite.Models; 

    namespace StudentTheatreGroupWebsite.DAL { 

    public interface IStudentRepository : IDisposable { 
       IEnumerable<Show> GetShows(); 
       Show GetShowByID(int ShowId); 
       void InsertShow(Show Show); 
       void DeleteShow(int ShowID); 
       void UpdateShow(Show Show); 
       void Save(); 
  }
 } 

我称之为“IShowRepository”,而不是IStudentRepository,不是吗?