Open dradoaica opened 2 years ago
Could you please provide more information to help replicating it?
List<AlertExecution> ae = new List<AlertExecution>(); ... using (Microsoft.Data.SqlClient.SqlConnection connection = ...) { await connection.InsertAsync(ae.AsEnumerable()); }
where AlertExecution : FullAuditedEntity<Guid> and has a member of generic type
Using Dapper 2.0.123 and DapperExtensions 1.7 A generic error with be raise in DapperImplementor in the lines reported. The code below work fine in version 1.6.3 but raise the reported issue in 1.7 How to Reproduce example:
public class RepositoryBase<TEntity> where TEntity : class
{
public DateTime CreationDate { get; set; }
public string CreationUser { get; set; }
}
public class UserLogin : RepositoryBase<UserLogin>
{
[Key]
public long UserID { get; set; }
public long EntityID { get; set; }
public static UserLogin Login()
{
using (SqlConnection cn = new SqlConnection(XXXXX))
{
cn.Update(userLogin);
}
return userLogin;
}
}
Exception:
This operation is only valid on generic types. at System.RuntimeType.GetGenericTypeDefinition() at DapperExtensions.DapperImplementor.AddParameter[T](T entity, DynamicParameters parameters, IMemberMap prop, Boolean useColumnAlias) at DapperExtensions.DapperImplementor.GetDynamicParameters[T](T entity, IClassMapper classMap, IList
1 sequenceColumn, IList
1 foreignKeys, IList1 ignoredColumns, Boolean useColumnAlias) at DapperExtensions.DapperImplementor.GetDynamicParameters[T](IClassMapper classMap, T entity, Boolean useColumnAlias) at DapperExtensions.DapperImplementor.InternalInsert[T](IDbConnection connection, T entity, IDbTransaction transaction, Nullable
1 commandTimeout, IClassMapper classMap, IList1 nonIdentityKeyProperties, IMemberMap identityColumn, IMemberMap triggerIdentityColumn, IList
1 sequenceIdentityColumn) at DapperExtensions.DapperAsyncImplementor.InternalInsertAsync[T](IDbConnection connection, T entity, IDbTransaction transaction, Nullable1 commandTimeout, IClassMapper classMap, IList
1 nonIdentityKeyProperties, IMemberMap identityColumn, IMemberMap triggerIdentityColumn, IList1 sequenceIdentityColumn) at DapperExtensions.DapperAsyncImplementor.InsertAsync[T](IDbConnection connection, T entity, IDbTransaction transaction, Nullable
1 commandTimeout)In DapperImplementor:
if (prop.MemberInfo.DeclaringType == typeof(bool) || (prop.MemberInfo.DeclaringType.IsGenericType && prop.MemberType.GetGenericTypeDefinition() == typeof(Nullable<>) && prop.MemberInfo.DeclaringType.GetGenericArguments()[0] == typeof(bool))) { ... }
There should be a check prop.MemberType.IsGenericType before prop.MemberType.GetGenericTypeDefinition()