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

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
magnus
Posts: 11
Joined: Mon 22 Aug 2011 11:07

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

Post by magnus » Thu 07 Feb 2013 12:35

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.

Shalex
Site Admin
Posts: 8248
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Fri 08 Feb 2013 10:47

Thank you for the detailed description of the issue. We will post here when the corresponding option is implemented.

Shalex
Site Admin
Posts: 8248
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Fri 22 Feb 2013 10:16

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.

Shalex
Site Admin
Posts: 8248
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Fri 05 Apr 2013 13:16

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.

Post Reply