How do I perform an insert to database and return inserted identity with Dapper?
I\'ve tried something like this:
string sql = \"DECLARE @ID int; \"
If you're using Dapper.SimpleSave:
//no safety checks
public static int Create(object param)
{
using (SqlConnection conn = new SqlConnection(GetConnectionString()))
{
conn.Open();
conn.Create((T)param);
return (int) (((T)param).GetType().GetProperties().Where(
x => x.CustomAttributes.Where(
y=>y.AttributeType.GetType() == typeof(Dapper.SimpleSave.PrimaryKeyAttribute).GetType()).Count()==1).First().GetValue(param));
}
}