gpt4 book ai didi

c# - 创建存储库

转载 作者:太空宇宙 更新时间:2023-11-03 11:23:49 25 4
gpt4 key购买 nike

我一直在用 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' does not implement interface member '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);
}
}
}

最佳答案

您有 InsertShows 而不是 InsertShow。您的界面需要 InsertShow

关于c# - 创建存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10125884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com