Insert returns 0 when using a string as an ExplicitKey on an object
Topic, this may also be related to DapperLib/Dapper#756 but i'm not sure if it's the same issue. Here is the object I am using:
using Dapper.Contrib.Extensions;
[Table("CostBooks.Staff")]
public class Staff
{
[ExplicitKey]
public string EmplNbr { get; set; }
public string AlphaName { get; set; }
public bool? IsFte { get; set; }
}
Here is the method I am calling. Will try to do this with async and see what happens.
[HttpPost]
public object CreateNewStaff([FromBody]Staff s)
{
using (IDbConnection db = DBAccessor.Connection())
{
if (s.EmplNbr != null)
{
var emplNbr = db.Insert<Staff>(s);
return emplNbr
}
else
{
return null;
}
}
}
Yea, the return type of both methods, is always a number. So by using a string key(Crappy archaic system that I probably wasn't even alive for when it was designed) it breaks the return type and always gives me back a 0. Would be nice if the return type changed based on the key of the type it used... not even sure if that's possible.
Tracking this in 2.0. We need to make the insert methods generic with the key as a type parameter which will resolve this. It's absolutely a breaking change, so tracking it as such.
@Adondriel In my experience it doesn't matter what the key type is because even an Explicit Key of type int will still always return 0 on Insert.