On a project with around 350 entities in the EDMX entity model, my team is experiencing lengthly waits when the first query happens and when the first save happens.
When profiling a simple case which runs a few queries and saves, a simple set of steps just to fire a query and save takes minutes.
The first query takes 47% of the overall time just the call that framework method that executes the query.
The first save takes 50% of the overall time just in System.Data.Objects.ObjectContext.SaveChanges.
Are there any good options to improve performance - this can be a drain on development time.
(Once the system hits production, it's annoying at startup but not a problem during the ongoing execution)
When you use context for the first time it generates mapping model defined in metadata. The option is to pregenerate this model and include pregenerated files in your application (but you must regenerate it each time you modify your EDMX).
Such a big model should be probably divided into multiple smaller models. I hardly believe that 350 entities form single domain which cannot be divided.
A single large EDMX will result in a large ObjectContext. everytime you do using(var ctx = new YourObjectContext())
it is going to construct a large object, initialize a lot of collections (probably 350 of them) and it is going to make your database operations CPU intensive. You will certainly hit performance challenges when you get high volume traffic.
I would suggest breaking the large WDMX into smaller EDMX and produce different ObjectContexts. You should put small number of logically grouped entities into one ObjectContext.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With