Description
I'm getting the following exception when calling dbContext.BulkSaveChanges():
System.NullReferenceException: Object reference not set to an instance of an object.
at EFCore.BulkExtensions.DbContextBulkTransactionSaveChanges.<>c.b__2_3(IEntityType e)
at EFCore.BulkExtensions.DbContextBulkTransactionSaveChanges.<>c__DisplayClass2_0.b__6(<>f__AnonymousType14 g) at Medallion.Collections.TopologicalSorter.TopologicalSort[TElement](ITopologicalSortProvider
1 provider)+MoveNext()
at System.Collections.Generic.List1.AddRange(IEnumerable
1 collection)
at System.Linq.Enumerable.ConcatIterator1.ToList() at EFCore.BulkExtensions.DbContextBulkTransactionSaveChanges.SaveChangesAsync(DbContext context, BulkConfig bulkConfig, Action
1 progress, Boolean isAsync, CancellationToken cancellationToken)
at EFCore.BulkExtensions.DbContextBulkTransactionSaveChanges.SaveChangesAsync(DbContext context, BulkConfig bulkConfig, Action1 progress, CancellationToken cancellationToken) at EFCore.BulkExtensions.DbContextBulkTransaction.ExecuteAsync[T](DbContext context, Type type, IEnumerable
1 entities, OperationType operationType, BulkConfig bulkConfig, Action`1 progress, CancellationToken cancellationToken)
I looks like e is null here
Func<IEntityType, IEnumerable<IEntityType>> getFks = delegate(IEntityType e)
{
IEntityType e2 = e;
return from x in e2.GetForeignKeys()
where x.PrincipalEntityType != e2
select x.PrincipalEntityType;
};
coming from
var first = TopologicalSortExtensions.OrderTopologicallyBy(enumerable, g => getFks(g.EntityType).SelectMany((IEntityType x) => addedLookup[x]), null);
When analyzing g I see that the contains the following information:
{ State = Added, Entities = System.Collections.Generic.List`1[System.Object], EntryType = AddressEntity, EntityType = }}
AddressEntity is an OwnsOne Relation type, so I guess that's the reason that there is no entity type?
I'm using version 8.0.1 and SQL Server.