Multiple AddType() are very slow

Jun 3, 2015 at 3:35 PM
Hi !

I'm currently working on a project using OpenNetCF.ORM, and I've got some problems about the initialization of the entities : it's really slow !
At starting, my application have to add 17 entities to the ORM. I call then 17 times the AddType() method, one time per entity. But I take about 12 seconds !

I don't know if it can change something, but I used a pattern singleton on me SqlCeDataStore.

Here is my class :
public class BaseRepository
    {
        private static SqlCeDataStore _store;

        public static SqlCeDataStore store()
        {
            if (_store == null)
            {
                //Stopwatch stopWatch = new Stopwatch();
                //stopWatch.Start();

                _store = new SqlCeDataStore((Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\MOBIGEST.sdf"));
                _store.AddType<Article>(); // 3.20
                _store.AddType<Depot>(); // 0.44
                _store.AddType<EnTeteAchat>(); // 0.80
                _store.AddType<EnTeteInventaire>(); // 0.20
                _store.AddType<EnTeteVente>(); // 0.81
                _store.AddType<EnTetePieceStock>(); // 0.78
                _store.AddType<LigneAchat>(); // 0.51
                _store.AddType<LigneInventaire>(); // 0.44
                _store.AddType<LigneVente>(); // 0.55
                _store.AddType<LignePieceStock>(); // 0.46
                _store.AddType<Lot>(); // 0.39
                _store.AddType<Parametres>(); // 0.21
                _store.AddType<Serie>(); // 0.28
                _store.AddType<Stock>(); // 0.41
                _store.AddType<Tier>(); // 0.81
                _store.AddType<LotPiece>(); // 0.48
                _store.AddType<Tracabilite>(); // 1.36

                // TOTAL : 12.91
                //stopWatch.Stop();
                
                //TimeSpan ts = stopWatch.Elapsed;
                //string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                //    ts.Hours, ts.Minutes, ts.Seconds,
                //    ts.Milliseconds / 10);
                //MessageBox.Show("Temps : " + elapsedTime);
            }
            return _store;
        }
    }
I would like to know if I'm doing something wrong or if it's normal ? What can I do to make it faster ? Maybe divide the AddTypes using lazy loading ? (I add entities only when I need them, and not all of them at the start)

Thank's

PS : Sorry for english mistakes, it's not my native language
Coordinator
Jun 3, 2015 at 8:55 PM
By default, the ORM will check that the tables match the entity structure. If you know they are correct (because you created them) you can skip the validation, which should be faster. For example:
_store.AddType<Article>(false);
Jun 4, 2015 at 4:04 PM
Thank's for this fast answer ! Thank's to you, my launching time have gone from 12 seconds to 2 seconds. Really, thank you :)