Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have to have some commonality in your repository interface. For example, you could this do:</p> <pre><code>public interface IRepository&lt;T&gt; { IEnumerable&lt;T&gt; GetList(); void DeleteBatch(IEnumerable&lt;T&gt; entities); // other methods here } </code></pre> <p>where you have:</p> <pre><code>public interface ICompanyRepository : IRepository&lt;T&gt; </code></pre> <p>and</p> <pre><code>public interface IDepartmentRepository : IRepository&lt;T&gt; </code></pre> <p>Then you can set up your base controller like this:</p> <pre><code>public abstract class DataController&lt;TModel&gt; : Controller { protected IRepository&lt;TModel&gt; repository; public DataController(IRepository&lt;TModel&gt; repository) { this.repository = repository; } [HttpPost] public ActionResult BatchDelete(long[] ids) { var entities = repository.GetList().Where(item =&gt; ids.Contains(item.ID)); repository.BatchDelete(entities); return RedirectToAction("Index"); } } </code></pre> <p><strong>UPDATE</strong> Then your CompanyController will look like this:</p> <pre><code>public CompanyController : DataController&lt;Company&gt; { public CompanyController(IRepository&lt;Company&gt; repository) : base(repository) { } } </code></pre> <p>This will do the trick.</p> <p>One other note of caution it looks like your GetList() is getting <em>all</em> entites from the database and then select the one you want to delete for the delete operation. Better to retrieve <em>only</em> the one you are interested from the database and save significant performance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload