Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This operation is only valid on generic types. #282

Open
dradoaica opened this issue Nov 19, 2021 · 3 comments
Open

This operation is only valid on generic types. #282

dradoaica opened this issue Nov 19, 2021 · 3 comments
Assignees
Labels
under investigation Issue is being analyzed

Comments

@dradoaica
Copy link

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, IList1 sequenceColumn, IList1 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, Nullable1 commandTimeout, IClassMapper classMap, IList1 nonIdentityKeyProperties, IMemberMap identityColumn, IMemberMap triggerIdentityColumn, IList1 sequenceIdentityColumn)
at DapperExtensions.DapperAsyncImplementor.InternalInsertAsync[T](IDbConnection connection, T entity, IDbTransaction transaction, Nullable1 commandTimeout, IClassMapper classMap, IList1 nonIdentityKeyProperties, IMemberMap identityColumn, IMemberMap triggerIdentityColumn, IList1 sequenceIdentityColumn) at DapperExtensions.DapperAsyncImplementor.InsertAsync[T](IDbConnection connection, T entity, IDbTransaction transaction, Nullable1 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()

@valfrid-ly valfrid-ly self-assigned this Feb 19, 2022
@valfrid-ly valfrid-ly added the under investigation Issue is being analyzed label Feb 19, 2022
@valfrid-ly
Copy link
Collaborator

Could you please provide more information to help replicating it?

@dradoaica
Copy link
Author

dradoaica commented Feb 21, 2022

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

@nroda1976
Copy link

nroda1976 commented Jan 6, 2023

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;
	}
}

ricardommatias pushed a commit to ricardommatias/Dapper-Extensions that referenced this issue Feb 6, 2024
@ricardommatias ricardommatias mentioned this issue Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
under investigation Issue is being analyzed
Projects
None yet
Development

No branches or pull requests

3 participants