-1

During an insert, the process errors with an invalid name error. Dapper is trying to pluralize the table name.

The mapper class is in the same namespace as the model, named after the table and the model lacks any other annotations, a simple POCO.

  //record is an instance of DMPERQ.cs
  var rqId = conn.Insert<DMPERQ>(record);

Error:

  Invalid object name 'DMPERQs'

The mapper class:

   public class DMPERQMapper: ClassMapper<DMPERQ>
   {

        public DMPERQMapper(){
           Table("DMPERQ");
           Map(m => m.RQID).Column("RQID").Key(KeyType.Identity);
           AutoMap();
        }

    }
Will Lopez
  • 2,089
  • 3
  • 40
  • 64

1 Answers1

1

The problem I think is that your custom classmapper is never being called. You can set a breakpoint and you will find that it never gets reached.

I tried this because DapperExtensions automatically makes a property ending in "id" and having the type of int an identity field (even when it isn't), and then excludes that property from the insert sql. This results in an ugly sql error if the database expects a value to be supplied.

I have encountered this in composite tables which have a composite key of two foreign keys, but no primary identity key. Technically, this is the way you are supposed to do these types of tables, but DapperExtensions does not like it at all.

The problem is how to secure and attach a reference to the ClassMapper instance, and I have seen nothing in anyone's documentation that indicates how to do this.

I ended up modifying DapperExtensions to fix the problem I was encountering, and you may have to do that as well.

The long term issue is: How do you attach a custom mapping to DapperExtensions and where do you put the code?

Some of the solutions indicate putting in the global.asax file, but that doesn't work.

Timothy Dooling
  • 470
  • 1
  • 4
  • 17