Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improving Entity Framework Performance during testing

I'm trying to reduce the startup time for tests against an EF 6x datastore. The tests are within a transaction and the db gets rolled back once done. I would appreciate any suggestions on how to retain an instance of the DbContext between test sessions so that EF doesn't have to go through the whole view generation process again?

I don't want to use mocks/fakes, non-Microsoft branch of EF and interactive views are already in place. Thank you.

like image 812
Vas Avatar asked Aug 24 '16 04:08

Vas


1 Answers

Different options. As you did not mentioned your aim of testing and there is not any code, the options are:

  1. If you are inserting many records into your tables, you can do a bulk insert. The best library for doing this is:EntityFramework.BulkInsert-ef6. You can install it through Nuget console.

  2. If you see slowness while working with data and you have many load/manipulation/save operations, you have to do in-memory operation as Sampath recommends.

  3. If you are loading data, just load the columns that you need. You also should use lazy loading option(which from your post, I think you know it well).

4.Some portion of the slowness could be because of the architecture of your database. The key column types have a considerable effect on Where operations!

like image 172
Hossein Abedi Avatar answered Nov 15 '22 10:11

Hossein Abedi