DapperLib / DapperLib/Dapper.Contrib
Dapper.Contrib "Insert" throws "Cannot convert null to 'int' because it is a non-nullable value type" when trying to call insert extension method while not using identity column at database
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 293
- Forks
- 109
- PR merge metrics
- No merged PRs in 30d
Description
this is the issue. create a table in the database without identity column. create its poco class and try to call insert method.
I would like to set id column from my application. that is why i am not using identity column.
i fould the reason when i debug the code. After I call Insert extension method, it tries to return @@Identity value as integer. but because of id is not identity, it returns null. so i get "Cannot convert null to 'int' because it is a non-nullable value type" exception message.
CREATE TABLE User(
[Id] [int] Primary key NOT NULL ,
[Name] nvarchar(50) NOT NULL
)
public class User
{
public Int32 Id {get;set;}
public String Name {get;set;}
}
using Dapper.Contrib.Extensions;
var connStr = "bla bla";
var connection = new SqlConnection(connStr);
connection.Open();
connection.Insert(new User { Id = 1, Name="Tugbay" });
connection.Close();
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Dapper.Contrib Insert extension method and reproduce the issue with the SQL table and C# User class shown in the report. Trace how the insert handles @@Identity when the Id is supplied by the application; done means inserting a row without an identity column no longer fails while identity-column inserts remain supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100