Skip to content

NullReferenceException when using OwnsOne #1654

Open
@Ben555555

Description

@Ben555555

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](ITopologicalSortProvider1 provider)+MoveNext()
at System.Collections.Generic.List1.AddRange(IEnumerable1 collection)
at System.Linq.Enumerable.ConcatIterator1.ToList() at EFCore.BulkExtensions.DbContextBulkTransactionSaveChanges.SaveChangesAsync(DbContext context, BulkConfig bulkConfig, Action1 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, IEnumerable1 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions