1
假设我的实体是如何让Dapper Dommel插入应用程序生成的主键?
public class AppUser
{
string Id { get; set; }
string Name { get; set; }
}
它看起来像默认短小精悍Dommel不插入ID字段。它会生成SQL非常接近这个:
insert into AppUser (Name) values ("Dapper") select cast(scope_identity() as int)
这个SQL是通过使用小巧精致的Dommel插入功能,像这样产生的:
using (var connection = new System.Data.SqlClient.SqlConnection(ConnectionString))
{
connection.Open();
connection.Insert<AppUser>(new User { Id = "someGuid", Name = "Dapper" });
}
我想它插入我所提供的ID列一个值,并且也不执行select cast(scope_identity()as int)查询。也就是说,我想这样的事情
insert into AppUser (Id, Name) values ("someGuid", "Dapper")
我似乎无法在文档中找到此。有谁知道如何做到这一点?
是的,你是绝对正确的,但不幸的是,因为它使用类似的方法插入它会破坏Dommel的目的(目标) ,删除(对象),更新(对象) - 没有硬编码SQL的好处。 –