asp .net mvc を使用してブログ アプリケーションを構築しようとしています。ブログはうまく機能していましたが、リポジトリ パターンを導入するのに飽きていません。動作する以下のコードから始めました。つまり、ブログ、コメントを追加し、それらを編集/削除できます。ただし、コードを少し変更したところ、すべてが失敗しました。何が悪いのかわかりません。
私はこのコードから始めました。
IBlogリポジトリ:
public interface IBlogRepository
{
IQueryable<Blog> FindAllBlogs();
Blog GetBlog(int id);
void Add(Blog blog);
void Update(Blog blog);
void Delete(Blog blog);
void Add(Comment comment);
//void Remove(Comment comment);
}
ブログリポジトリ:
public class BlogRepository : IBlogRepository
{
....
public void Add(Blog blog)
{
db.Blogs.Add(blog);
db.SaveChanges();
}
....
}
ブログ管理者:
IBlogRepository blogrepository;
public BlogController()
{
blogrepository = new BlogRepository();
}
.....
public ActionResult Create(Blog blog)
{
if (ModelState.IsValid)
{
blog.Content = Regex.Replace(blog.Content, " {2,}", x => x.Value.Replace(" ", " "));
blog.Content = blog.Content.Replace("\n", "<br/>");
blogrepository.Add(blog);
return RedirectToAction("Index");
}
return View(blog);
}
.....
}
変更と機能しないコードは次のとおりです。
IBlogリポジトリ:
public interface IBlogRepository
{
IQueryable<Blog> FindAllBlogs();
Blog GetBlog(int id);
T Update<T>(T entity) where T : class;
T Add<T>(T entity) where T : class;
T Delete<T>(T entity) where T : class;
}
ブログリポジトリ:
public class BlogRepository : BlogDb, IBlogRepository {
...
T INPLHBlogRepository.Add<T>(T entity)
{
return Set<T>().Add(entity);
}
...
}
私は何を壊しましたか?どうもありがとう