1

我正在尝试使用以下教程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);
        }
    }
}
4

1 回答 1

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,不是吗?

于 2012-04-12T15:43:51.850 回答