I am currently using EntityFramework.BulkInsert-ef6-ext by hugocl. My software is currently running daily and I am getting "No table mappings provided." once in a while, around 1 to 2 times a week while the rest of the days it runs fine.
Below is the error stack trace:
at EntityFramework.BulkInsert.Helpers.MappedDataReader`1..ctor(IEnumerable`1 enumerable, IEfBulkInsertProvider provider)
at EntityFramework.BulkInsert.Providers.EfSqlBulkInsertProviderWithMappedDataReader.Run[T](IEnumerable`1 entities, SqlTransaction transaction)
at EntityFramework.BulkInsert.Providers.ProviderBase`2.Run[T](IEnumerable`1 entities, IDbTransaction transaction)
at EntityFramework.BulkInsert.Providers.ProviderBase`2.Run[T](IEnumerable`1 entities)
at EntityFramework.BulkInsert.Extensions.BulkInsertExtension.BulkInsert[T](DbContext context, IEnumerable`1 entities, BulkInsertOptions options)
at EntityFramework.BulkInsert.Extensions.BulkInsertExtension.BulkInsert[T](DbContext context, IEnumerable`1 entities, SqlBulkCopyOptions sqlBulkCopyOptions, Nullable`1 batchSize)
at EntityFramework.BulkInsert.Extensions.BulkInsertExtension.BulkInsert[T](DbContext context, IEnumerable`1 entities, Nullable`1 batchSize)
at ADUtility.Logic.Task.GetDLAssociatesBeforeRunTask.<>c__DisplayClass1_0.<Execute>b__0(TP_DLs dl) in ...
Anyone can provide any ideas on why this is happening?
Below is the code I am using:
var dlAssociatesBeforeRun = adHelper.GetDLAssociates(dl.DLName)
.Select(x =>
new TP_DLAssociatesBeforeRun
{
DLID = dl.ID,
ADUsername = x.ADUsername,
CreateDate = DateTime.Now,
CreateBy = "ADUtility.CLI",
UpdateDate = DateTime.Now,
UpdateBy = "ADUtility.CLI"
}).ToList();
_logger.Trace($"Detected {dlAssociatesBeforeRun.Count} for DL {dl.DLName}");
// ReSharper disable once InvertIf
if (dlAssociatesBeforeRun.Any())
{
db.BulkInsert(dlAssociatesBeforeRun);
db.SaveChanges();
Below is the GetDLAssociates method which is basically just returns a list of view model objects:
public List<DLAssociateViewModel> GetDLAssociates(string groupName, PrincipalContext context = null)
{
var dlAssociate = new List<DLAssociateViewModel>();
var group = GroupPrincipal.FindByIdentity(context ?? GlobalContext, groupName);
if (group == null)
{
throw new Exception("DL not found on Active Directory");
}
dlAssociate.AddRange(group.Members.OfType<UserPrincipal>()
.Select(member => new DLAssociateViewModel
{
DLName = groupName,
ADUsername = string.IsNullOrEmpty(member.EmployeeId) ? member.SamAccountName : member.EmployeeId,
}));
return dlAssociate;
}