Page 1 of 1

Split up the OnModelCreating method into smaller methods (fluent mapping)

Posted: Thu 07 Feb 2013 12:35
by magnus
We just ran into a very obscure and somewhat comical issue where we were getting a StackOverflowException in the OnModelCreating method in certain cases. As it turned out it was caused by the OnModelCreating method having gotten so big that it was breaking the default IIS 32-bit stack limit of 256 KB, presumably because the calls to Entity<T> command etc. keep growing the stack. We have about 200 entities in our model, and we're clearly somewhere between the aforementioned IIS limit and the more standard .NET limit of 1 MB.

We've now modified our version of the DbContext template so each entity gets its own method, and that fixed the issue. But we'd prefer it if this was the standard behavior of your DbContext template.

On a related note, Visual Studio often struggles really badly when you try to open the generated file with the DbContext in it, presumably because it's hard for it to seamlessly compile all the fluent mapping code on the fly. Perhaps there could be an option that allowed splitting the DbContext across multiple files as well? This is a much less important point than the one about splitting OnModelCreating into smaller methods though.

Re: Split up the OnModelCreating method into smaller methods (fluent mapping)

Posted: Fri 08 Feb 2013 10:47
by Shalex
Thank you for the detailed description of the issue. We will post here when the corresponding option is implemented.

Re: Split up the OnModelCreating method into smaller methods (fluent mapping)

Posted: Fri 22 Feb 2013 10:16
by Shalex
Starting from the 5.1 version of Entity Developer, the Configuration Per Class option of the DbContext template will be implemented. If you turn it on, fluent mapping for each class will be placed in a separate configuration class, and the instance of the configuration class will be created in the OnModelCreating method and added to the corresponding collection. We will post here when Entity Developer v 5.1 is released.

Re: Split up the OnModelCreating method into smaller methods (fluent mapping)

Posted: Fri 05 Apr 2013 13:16
by Shalex
New version of Entity Developer 5.5 is released!
It can be downloaded from http://www.devart.com/entitydeveloper/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=32&t=26309.

The name of the corresponding property of DbContext template is Mapping Generation Strategy. If it is set to UseConfigurations, the fluent mapping for each model class will be placed to the separate configuration class when generating code. The property can be used, if Fluent Mapping is turned on.