Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException when using OwnsOne #1654

Open
Ben555555 opened this issue Jan 16, 2025 · 0 comments
Open

NullReferenceException when using OwnsOne #1654

Ben555555 opened this issue Jan 16, 2025 · 0 comments

Comments

@Ben555555
Copy link

Ben555555 commented Jan 16, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant