Esempio n. 1
0
        public void Load <T>(IEnumerable <T> ts, bool save) where T : class
        {
            using (var context = new AccountingContext())
            {
                var dbSet = context
                            .GetType()
                            .GetProperty(this.pluralizationService.Pluralize(typeof(T).Name))
                            .GetValue(context, null) as DbSet <T>;

                if (dbSet == null)
                {
                    throw new Exception("could not cast to DbSet<T> for T = " + typeof(T).Name);
                }

                foreach (var t in ts)
                {
                    dbSet.AddOrUpdate(t);
                }

                if (save)
                {
                    context.SaveChanges();
                }
            }
        }