Suppose my entity is
public class AppUser
{
string Id { get; set; }
string Name { get; set; }
}
It looks like by default Dapper Dommel doesn't insert the Id field. It would generate SQL very close to this:
insert into AppUser (Name) values ("Dapper") select cast(scope_identity() as int)
This SQL is generated by using the Dapper Dommel Insert function like so:
using (var connection = new System.Data.SqlClient.SqlConnection(ConnectionString))
{
connection.Open();
connection.Insert<AppUser>(new User { Id = "someGuid", Name = "Dapper" });
}
I would like it to insert the Id column that I have provided a value for and also not perform the select cast(scope_identity() as int) query. That is, I would like something like this
insert into AppUser (Id, Name) values ("someGuid", "Dapper")
I can't seem to find this in the documentation. Does anyone know how to achieve this?
I'm not familiar with Dommel, but you can just use .Execute:
_dbConnection.Execute(@"insert into AppUser (Id, Name)
values (@Id, @Name)", new {Id = 1, Name = "Foo"});