Dapper Property Types

dapper mapping types

Question

If I have a table such as the following:

CREATE TABLE  MYTABLE
(
    ID NUMBER(15) NOT NULL CONSTRAINT IFS_ROUTINE_ADGROUP_PK_PRIM PRIMARY KEY, 
    NUMBER_COLUMN NUMBER(15)  NOT NULL,
    TEXT_COLUMN VARCHAR2 (50)  NOT NULL
)  ;

If I have one single record in MYTABLE in which the TEXT_COLUMN column contains '12345' as its value and my model is as following:

public class MyModel
{
    public long ID;
    public long NUMBER_COLUMN;
    public long TEXT_COLUMN; //this is an error (since the type in the database is text)
}

In a test scenario in which this single row is returned everything would return fine. If there are, however, text values coming from the database, an error will occur.

The following questions arise:

  1. Is it possible to prevent this type of error through Dapper only? Such as throwing an exception if the type from the database is mismatching the one in the model?
  2. Should I, alternatively, operate with the assumption that Dapper should work with well mapped objects (due to its performance gains) ?

Accepted Answer

The acceptable set of answers for the time being:

  1. No
  2. Mapping should be carefully done along with tests. Dapper, won't care about matching types from the model in the application and those in the database.

Thanks, @Shyju for your cooperation & time.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why