Dapper.Contrib
Dapper.Contrib copied to clipboard
Insert/Update of interfaced type
Hello! I'm found some error in Insert/Update operation if I pass interfaced type.
public int SaveAbstract(IObjectBase item)
{
item._Updated = DateTime.UtcNow;
if (item.ID > 0) c.Update(item, transaction: tr, commandTimeout: commandTimeout);
else item.ID = (int)c.Insert(item, transaction: tr, commandTimeout: commandTimeout);
cache.Remove(item.GetType().FullName.makeCacheKey());
return item.ID;
}
Currently, Update and Insert method can't find table attribute on IObjectBase and substitute object class name. I'm start investigate and found some lines in this methods:
var type = typeof(T);
I think this line need to be replaced to entityToUpdate.GetType() because Insert/Update need to be know real type of passed item. After changes Insert/Update working correctly.
There is already an issue about this: DapperLib/Dapper#629