我目前使用的是由hugocl EntityFramework.BulkInsert-ef6-ext。我的軟件目前每天都在運行,並且正在收到「沒有提供表格映射」。偶爾有一次,每週大約1到2次,其餘的日子都很好。沒有提供表映射
下面是錯誤堆棧跟蹤:
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 ...
任何人都可以提供關於爲什麼發生這種情況的任何想法?
下面是我使用的代碼:
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();
下面是GetDLAssociates方法,它基本上只是返回視圖模型對象的列表:
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;
}
請將您的代碼直接添加到問題中。 – timiTao