title: How to properly "Singularize" table names with Dapper.Contrib?
body: <p>I have a .Net Core 3.1 Console application.</p>
  
  <p>In SQL Server database I have tables with singular names, the same as my POCO classes, which is convenient for matching and maintaining.</p>
  
  <p>For Insert, Update and Delete operations I want to use <code>Dapper.Contrib</code> library. But when I run Insert function Dapper pluralize table names in generated SQL queries.</p>
  
  <p>SQL table "Student":</p>
  
  <pre><code>CREATE TABLE Student
      StudentId int NOT NULL PRIMARY KEY,
      FirstName varchar(50),
      LastName varchar(50)
  </code></pre>
  
  <p>C# code</p>
  
  <pre><code>public class Student
  {
      public int StudentId {get; set;}
      public string FirstName {get; set;}
      public string LastName {get; set;}
  }
  
  
  class Program
  {
      static void Main(string[] args)
      {
          var students = new List&lt;Student&gt;()
              {
                  new Student { StudentId = 1, FirstName = "John", LastName = "Doe"},
                  new Student { StudentId = 2, FirstName = "Tony", LastName = "Montana"}
              }
  
          long result;
          using (var cn = new SqlConnection(connString))
              {
                          result = cn.Insert(students);
              }
      }
  }
  </code></pre>
  
  <p>On output I get an exception:</p>
  
  <blockquote>
    <p>Invalid object name 'Students'.</p>
  </blockquote>
  
  <p>I surfed around to find a solution, but couldn't find a working example. In general there two kinds of recommendations:</p>
  
  <ol>
  <li><p><strong>Use data annotations</strong>. This one is not suitable for me, as there are a lot of POCO objects created automatically from a database using <code>Scaffold-DbContext</code>. During the development process, I make changes in database and then re-create POCOs again. This operation deletes all changes made in generated POCO classes.</p></li>
  <li><p>Use of <code>SqlMapperExtensions</code> delegate:</p>
  
  <p><code>SqlMapperExtensions.TableNameMapper = (type) =&gt; {
      // do something here to pluralize the name of the type
      return type.Name;
  };</code></p></li>
  </ol>
  
  <p>I don't know how to properly use this delegate, and where to place it.
  I experimented a while, but I am sure that I don't use it properly:</p>
  
  <pre><code>using (var cn = new SqlConnection(connString))
      {
              SqlMapperExtensions.TableNameMapper = (type) =&gt;
              {
                  type.Name.Remove(type.Name.Length - 1, 1);
                  return type.Name;
              };
              result = cn.Insert(students);
      }
  </code></pre>
  
  <p>On this line of code <code>type.Name.Remove(type.Name.Length - 1, 1);</code> I tried to implement a function which cuts-off the last letter in the name of the type <code>Student</code>, assuming that Dapper adds the last letter "s" to the name of the class, and I remove it in my implementation.
  Example: <code>Student =&gt; Students =&gt; Student(s) =&gt; Student</code>.</p>
  
  <p>Long story short - I couldn't find a solution of how to implement a function that will "singularize" my table names.</p>
  
  <p>How should I use <code>SqlMapperExtensions</code> or maybe there is another approach which may "singularize" table names without making changes in POCO classes?</p>