Search code examples
c#sql-serverdapper

No mapping exists from DbType UInt64 to a known SqlDbType. Dapper C#


I have a table field(TotalPrice) in our SQL Server 2016 database with numeric(20, 3) data type.

I used ulong type as my C# property type.

public ulong TotalPrice { get; set; }

When I want to insert a record in my Table the following exception occurred.

No mapping exists from DbType UInt64 to a known SqlDbType

My C# code to insert a record:

const string queryInsertInvoice = @"
INSERT INTO Invoice (CustomerId, Number, TotalPrice, LatestStatusDateTime) 
VALUES (@CustomerId, @Number, @TotalPrice, @LatestStatusDateTime)
SELECT SCOPE_IDENTITY();";

var invoiceId = await dbConnection.QueryFirstOrDefaultAsync<int>(queryInsertInvoice, invoice);

How can I handle this situation with Dapper 2.0.53 ?


Solution

  • Just change TotalPrice type to decimal.

    public decimal TotalPrice { get; set; }
    

    https://learn.microsoft.com/en-us/sql/t-sql/data-types/decimal-and-numeric-transact-sql?view=sql-server-ver15