Open eymenkhater opened 2 years ago
Hello @eymenkhater ,
The issue happens because you are currently using a global mapping inside a method. This means every time the method is called, you currently rewrite this mapping and an error happens due to concurrency.
When using a global mapping, the code should be called only once such as during the application startup. This is still possible to use a mapping inside a method but you need to use an Instance Context Mapping
for this.
See the following documentation to learn more about the mapping: https://dapper-plus.net/getting-started-mapping
You will find out the difference between:
and mapper key for handling more special scenarios such as this one you wish to ignore the StoragePath
.
Let me know if that explains correctly why this happens and how you can fix it.
Best Regards,
Jon
Hello @JonathanMagnan,
I have updated the method. I moved the global method into a static class (DapperPlusGlobalMapping) inside the SetGlobalMapping method and called the method from Startup but I still get the same error. Is there a point I missed?
public async Task<bool> BulkUpdateAsync(List<ProductItemStock> productItemStocks)
{
using (var connection = await _postgreSQLDbConnectionFactory.CreateAsync())
{
connection.BulkUpdate(productItemStocks);
}
return true;
}
DapperPlusGlobalMapping.cs
public static void SetGlobalMapping()
{
DapperPlusManager.Entity<ProductItemStock>().Identity(q => q.Id, true).Ignore(q => q.StoragePath);
}
StartupSetup.cs
public static IServiceCollection AddOrderModuleInfrastructure(this IServiceCollection services, IConfiguration configuration)
{
DapperPlusGlobalMapping.SetGlobalMapping();
return services;
}
Hello @eymenkhater ,
I don't think you miss anything. But perhaps there is a little piece of the puzzle we are missing.
Here is a quick fiddle I made with your mapping: https://dotnetfiddle.net/SDfDZ1
Is it possible for you to update it or provide us a project with the minimum code required to reproduce this error? You can send it in private if needed here: info@zzzprojects.com
There is a good chance that indeed our library has an issue with your inheritance for example but I'm not sure how is done your _Domain
interface and StoragePath
class.
Best Regards,
Jon
Hello @JonathanMagnan,
Sounds good. I will send you soon.
Hello @eymenkhater ,
Thank you for the project, we indeed have an error on our side.
The problem is that the entity ProductItemStock
is mapped to the table to productitemstock
(singular) but your table name is productitemstocks
(plural).
To fix it, you can specify the table mapping to fix this issue this way:
DapperPlusManager.Entity<ProductItemStock>().Table("productitemstocks").Identity(q => q.Id, true).Ignore(q => q.StoragePath);
On our side, my developer will work on the error message to make sure we make it more explicit about what is happening. We might also look to try to map information to a table name in the plural form when the table name in the singular form (default) is not found.
Hello there! Trying to execute BulkUpdate action but getting the following error:
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1] An unhandled exception has occurred while executing the request. System.Exception: An error occured while retrieving the InformationSchemaTable information. See the inner exception for details. ---> System.ArgumentNullException: Value cannot be null. (Parameter 'key') at System.Collections.Generic.Dictionary
2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary
2.Add(TKey key, TValue value) at System.Linq.Enumerable.ToDictionary[TSource,TKey](List1 source, Func
2 keySelector, IEqualityComparer1 comparer) at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable
1 source, Func2 keySelector, IEqualityComparer
1 comparer) at .(Boolean , String[] ) at .() at Z.BulkOperations.BulkOperation.() --- End of inner exception stack trace --- at Z.BulkOperations.BulkOperation.() at Z.BulkOperations.BulkOperation.Execute() at Z.BulkOperations.BulkOperation.BulkUpdate() at Z.Dapper.Plus.DapperPlusAction.Execute() at Z.Dapper.Plus.DapperPlusActionSet1.AddAction(String mapperKey, DapperPlusActionKind actionKind, TEntity item) at Z.Dapper.Plus.DapperPlusActionSet
1.DapperPlusActionSetBuilder(DapperPlusContext context, IDbConnection connection, IDbTransaction transaction, String mapperKey, DapperPlusActionKind actionKind, TEntity item, Func2[] selectors) at Z.Dapper.Plus.DapperPlusActionSet
1..ctor(DapperPlusContext context, IDbConnection connection, String mapperKey, DapperPlusActionKind actionKind, TEntity item, Func2[] selectors) at Z.Dapper.Plus.DapperPlusExtensions.BulkUpdate[T](IDbConnection connection, String mapperKey, T item, Func
2[] selectors) at Z.Dapper.Plus.DapperPlusExtensions.BulkUpdate[T](IDbConnection connection, T item, Func`2[] selectors)The method
Details of object
I tried the update action with Dapper.Contrib and was able to successfully update.
The object values:
Packages which I using: Z.Dapper.Plus version 4.0.9 Npgsql version 5.0.7