我一直在用 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 作为帮助我创建存储库的指导。我创建了一个包含以下代码的类。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TheatreGroup.Models;
namespace TheatreGroup.DAL
{
public interface IShowRepository : IDisposable
{
IEnumerable<Show> GetShows();
Show GetShowByID(int showId);
void InsertShow(Show name);
void DeleteShow(int showID);
void UpdateShow(Show name);
void Save();
}
}
但是当我来创建第二堂课时,我得到一个错误说:
TheatreGroup.DAL.ShowRepository'没有实现接口成员'TheatreGroup.DAL.IShowRepository.InsertShow(TheatreGroup.Models.Show)'。
错误在5线向下(围绕左右)
using System.Data;
using TheatreGroup.Models;
namespace TheatreGroup.DAL
{
public class ShowRepository: IShowRepository, IDisposable
{
private TheatreContext context;
public ShowRepository(TheatreContext context)
{
this.context = context;
}
public IEnumerable<Show> GetShows()
{
return context.Shows.ToList();
}
public Show GetShowByID(int id)
{
return context.Shows.Find(id);
}
public void InsertShows(Show name)
{
context.Shows.Add(name);
}
public void DeleteShow(int showID)
{
Show shows = context.Shows.Find(showID);
context.Shows.Remove(shows);
}
public void UpdateShow(Show name)
{
context.Entry(name).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);
}
}
}
答案 0 :(得分:2)
您InsertShows
没有InsertShow
。您的界面需要InsertShow
。