EF6 data context throws stackoverflow exception after SqlBulkCopy insrt large data

entity-framework-6 sqlbulkcopy wpf

Question

I have a situation, consider:

  1. SQL Server 2014 Database with table T1.
  2. WPF application that has EF6 to maintain data in table T1.

Application is running OK.

When app starts, if table T1 is empty (0 records), SqlBulkCopy is used to insert 5000 records in T1 allowing triggers to fire and constraints check, the result is:

  1. Table T1 is filled with 5000 records successfully.
  2. All triggers were fired and constraints were checked and non of them being violated.
  3. The problem is, after the SqlBulkCopy.WriteToServer is completed, context.T1 will crash once tried to enumerate it, throwing StackOverfolow exception.

I have tried to initialize the context but no success.

The procedure will succeed in two cases:

  1. If the app is closed and re run, context will read T1 successfully.
  2. If all steps were applied where T1 has at least one record (app is started with non empty T1 table).

What could cause the StackOverflow exception.

Popular Answer

Ok, problem solved, just in case someone else would face a similar error, I will share my solution.

I have modified the T4 template to enable the EDM to produce entities from my database that:

  1. Implement the INotifyPropertyChanged.

  2. Apply Data Validation by implementing the INotifyDataErrorInfo and using DataAnnotations by checking validation rules in Metadata separate class.

That caused the StackOverFlow excepetion.

Disabling the Property Validation solved the problem.

So, Data Validation is not welcomed as SqlBulkCopy while WriteToServer is in progress.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why