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

Unable to cast object of type 'System.Int64' to type 'System.Nullable`1[System.Int32]' #1429

Open
boomgetchopped opened this issue Mar 5, 2024 · 1 comment
Labels

Comments

@boomgetchopped
Copy link

boomgetchopped commented Mar 5, 2024

Using version 8.0.1. I get this error when saving sub entities. The FK is a long. I'm wondering that has anything to do with it?

It fails at the bulk insert subEntities line with this error:

` executionStrategy.Execute(
() =>
{
//_db.BillingHeaders.AddRange(headerstoInsert);
//_db.BulkSaveChanges();

			using (var transaction = _db.Database.BeginTransaction())
			{
				_db.BulkInsert(headerstoInsert, new BulkConfig { SetOutputIdentity = true });
				var subEntities = new List<BillingDetail>();
				foreach (var entity in headerstoInsert)
				{
					foreach (var subEntity in entity.BillingDetails)
					{
						subEntity.BillingId = entity.BillingId; // sets FK to match its linked PK that was generated in DB
					}
					subEntities.AddRange(entity.BillingDetails);
				}
				_db.BulkInsert(subEntities);
				transaction.Commit();
			}

		});`
@borisdj
Copy link
Owner

borisdj commented Mar 12, 2024

Can you write full code snippet or entire test the for reproduction of the issue, so Entity class, and context config if any.
Try yo strip ti to minimum components that still throws the exception.

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

No branches or pull requests

2 participants