Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 扩展特定于实体的存储库C类_C#_Entity Framework_Repository Pattern - Fatal编程技术网

C# 扩展特定于实体的存储库C类

C# 扩展特定于实体的存储库C类,c#,entity-framework,repository-pattern,C#,Entity Framework,Repository Pattern,我目前有一个entity framework repository类,它基于我在网上找到的以下代码 这很好,但是,我想创建其他方法来为特定实体执行特定功能。例如,如果我有一篇博客文章需要按文章类型过滤,我可以在我的控制器中编写 SqlRepository<Blog, MyContext> blogPostRepo = new SqlRepository<Blog, MyContext>(dbContext); LinkedList<Blo

我目前有一个entity framework repository类,它基于我在网上找到的以下代码

这很好,但是,我想创建其他方法来为特定实体执行特定功能。例如,如果我有一篇博客文章需要按文章类型过滤,我可以在我的控制器中编写

 SqlRepository<Blog, MyContext> blogPostRepo = new SqlRepository<Blog, MyContext>(dbContext);
            LinkedList<Blog> blogPosts = (LinkedList<Blog>)blogPostRepo.Set<Blog>().Where(p => p.PostType.Id.Equals(2));
SqlRepository blogPostRepo=newsqlrepository(dbContext);
LinkedList blogPosts=(LinkedList)blogPostRepo.Set()。其中(p=>p.PostType.Id.Equals(2));
然而,理想情况下,我只想扩展基本的SqlRepository类来创建一个BlogPostRepository,以尝试保持代码的整洁。我现在被BlogPostRepository中的类签名卡住了。如何编写扩展以下基类的类/

 public class SqlRepository<TEntity, TContext> : IRepository<TEntity>, IDisposable
         where TEntity : class
         where TContext : DbContext
    {
enter code here
公共类SqlRepository:IRepository,IDisposable 地点:班级 其中TContext:DbContext { 在这里输入代码 创建如下类:

public class BlogRepository : SqlRepository<Blog, MyContext>
公共类BlogRepository:SqlRepository
向派生类添加一个构造函数,并使用必要的参数调用基类的构造函数(Ref:)

创建类,如:

public class BlogRepository : SqlRepository<Blog, MyContext>
公共类BlogRepository:SqlRepository
向派生类添加一个构造函数,其中包含调用基类构造函数的必要参数(Ref:)