arch / UnitOfWork

A plugin for Microsoft.EntityFrameworkCore to support repository, unit of work patterns, multiple database with distributed transaction supported, and MySQL multiple databases/tables sharding supported.
MIT License
1.32k stars 343 forks source link

InsertAsync() doesn't work with lists correctly #111

Closed Hoshani closed 4 years ago

Hoshani commented 5 years ago

Describe the bug

InsertAsync() doesn't add objects of type list

To Reproduce

All you have to do is to add a list as a parameter in there instead of adding one element

doesn't throw any errors, even with try catch block and nothing changes in the database

......
var entities = dtos.ToEntity<TDto, TEntity>(_mapper);
await _repository.InsertAsync(entities);
int affectedRows = await CommitAsync(); // in this case affectedRows == 0
......

Expected behavior

It should add all objects of list

Current Workaround

Adding objects one by one

......
var entities = dtos.ToEntity<TDto, TEntity>(_mapper);
foreach (var entity in entities)
{
await _repository.InsertAsync(entity);
}
int affectedRows = await CommitAsync(); // in this case affectedRows > 0
......