Dapper.Contrib icon indicating copy to clipboard operation
Dapper.Contrib copied to clipboard

Insert/Update of interfaced type

Open DBalashov opened this issue 6 years ago • 1 comments

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.

DBalashov avatar Jul 28 '17 07:07 DBalashov

There is already an issue about this: DapperLib/Dapper#629

cremor avatar Aug 07 '17 19:08 cremor