title: asp.net Core Creating DbSet for Interface
body: <p>I have a generic repository which does all the usual CRUD operations</p>
  
  <pre><code>   public class Repository&lt;T&gt; : IRepository&lt;T&gt;
      where T : class
  {
      private readonly CmcContext _context;
  
      public Repository(CmcContext context)
      {
          _context = context;
      }
  
      public void Add(T entity)
      {
          _context.Entry(entity).State = EntityState.Added;
          Save();
      }
  
      public void Delete(T entity)
      {
          _context.Set&lt;T&gt;().Remove(entity);
          Save();
      }
  
      public void Update(T entity)
      {
          var entry = _context.Entry(entity);
          entry.State = EntityState.Modified;
          _context.Set&lt;T&gt;().Attach(entity);
          Save();
      }
  
      public IEnumerable&lt;T&gt; Get(params Expression&lt;Func&lt;T, object&gt;&gt;[] navigationProperties)
      {
          IQueryable&lt;T&gt; dbQuery = _context.Set&lt;T&gt;();
  
          //Apply eager loading
          foreach (Expression&lt;Func&lt;T, object&gt;&gt; navigationProperty in navigationProperties)
              dbQuery = dbQuery.Include&lt;T, object&gt;(navigationProperty);
  
          return dbQuery
               .AsNoTracking()
               .ToList&lt;T&gt;();
      }
  
      public T GetById(Guid id)
      {
          return _context.Set&lt;T&gt;().Find(id);
      }
  
      public void Save()
      {
          _context.SaveChanges();
      }
  
  }
  </code></pre>
  
  <p>Interface:</p>
  
  <pre><code>    public interface IRepository&lt;T&gt; where T : class
  {
      void Add(T entity);
      void Delete(T entity);
      void Update(T entity);
      IEnumerable&lt;T&gt; Get(params Expression&lt;Func&lt;T, object&gt;&gt;[] navigationProperties);
      T GetById(Guid id);
      void Save();
  
  }
  </code></pre>
  
  <p>the class repository:</p>
  
  <pre><code> public class Definition : Repository&lt;Definition&gt;, IDefinition
  {
  
      private static CmcContext _context;
      public Definition()
          : base(_context)
      {
  
      }
  
  }
  </code></pre>
  
  <p>and the call to the repository from the controller:</p>
  
  <pre><code>  private readonly IRepository&lt;IDefinition&gt; _definition;
  
      public DefinitionController(IRepository&lt;IDefinition&gt; definition)
      {
          _definition = definition;
      }
  
      [HttpGet("")]
      public IActionResult Get()
      {
          return Ok(_definition.Get());
      }
  </code></pre>
  
  <p>which is then set up in the ConfigureServices:</p>
  
  <pre><code>services.AddScoped&lt;IDefinition, Repositorys.Pricefile.Column.Definition&gt;();
  
          services.AddScoped(typeof(IRepository&lt;&gt;), typeof(Models.Repository&lt;&gt;));
  </code></pre>
  
  <p>My issue is that when i call any of the actions in the Repository is that its passing the interface in to the repository class which IDeffinition isnt in the EF model </p>
  
  <pre><code>System.InvalidOperationException: 'Cannot create a DbSet for 'IDefinition' because this type is not included in the model for the context.'
  </code></pre>
  
  <p>I'm not sure how to resolve this issue or if what i am trying to do is even possible?</p>