0

Using EF 6 and "Code First from database" it generates a "OnModelCreating" that is 20k lines approximately 688k of code against our large (650+ tables) database. This causes IIS to append as it is larger than the 32-bit 256kb stack limit. I do not think there is any way to have EF put the Fluent API model bindings per class, which would clearly solve this problem.

To solve this problem currently I have to make smaller "OnModelCreatingX" methods and call those from the "OnModelCreating" method - ya rly.

Is there any refactor tool to take a huge method and split that method into smaller methods?

CmdrTallen
  • 2,264
  • 4
  • 28
  • 50
  • Why does it matter how big is the source code file since it gets compiled into dlls? – Vidmantas Blazevicius Jul 19 '19 at 14:47
  • Because it throws a overflow exception on the W3C.exe process. Same problem as this guy has https://forums.devart.com/viewtopic.php?t=25837 – CmdrTallen Jul 19 '19 at 14:52
  • But if you are using "Code First" you are in control how big your methods will be. It's kinda confusing as it stands as to why you are experiencing this. – Vidmantas Blazevicius Jul 19 '19 at 14:55
  • The "OnModelCreating" method is generated by using the "Code First from Database" generation when used against an existing database. https://learn.microsoft.com/en-us/ef/ef6/modeling/code-first/workflows/existing-database – CmdrTallen Jul 19 '19 at 14:59
  • Ok, I see what you mean now. I guess it might just have to be a one off to split those methods into smaller classes since you will only ever generate the initial files once. – Vidmantas Blazevicius Jul 19 '19 at 15:30
  • When changes are done to our schema (which is unfortunately frequently) we use "Code First from database" to update existing POCO classes, create new POCO classes and update the DBContext. When this happens the "OnModelCreating" gets regenerated as well and requires manually splitting up into 4 different "OnModelCreatingX" methods. – CmdrTallen Jul 19 '19 at 15:40

1 Answers1

0

Assuming you have to edit the generated code, could you try to split it out it into different files and convert it to a partial class?

Andrew Simon
  • 148
  • 7
  • A single (too large) "OnModelCreating" is generated by the "Code First from Database" in the generated DBContext class. Creating a partial class won't solve this as the single "OnModelCreating" method is generated by the EF tool. – CmdrTallen Jul 19 '19 at 15:15