public void AddBulkWithoutPackage(IEnumerable <T> entities)
        {
            _entities.Configuration.AutoDetectChangesEnabled = false;
            int page = 1000;
            int skip = 0;

            int             total = entities.Count();
            IEnumerable <T> chnuckEntities;


            while (skip < total)
            {
                if (skip + page > total)
                {
                    chnuckEntities = entities.Skip(skip);
                    skip           = total;
                }
                else
                {
                    chnuckEntities = entities.Skip(skip).Take(page);
                    skip          += page;
                }
                var ctx       = new AssetContext();
                var tempDBSet = ctx.Set <T>();

                //////////////////////
                var newThread = new Task(() =>
                {
                    foreach (var e in chnuckEntities)
                    {
                        tempDBSet.Add(e);
                    }
                    ctx.SaveChanges();
                });
                // Start the task.
                newThread.Start();

                // Output a message from the calling thread.
                Console.WriteLine("start thread to save bulk with page size'{0}'.", page);
                //newThread.Wait();
                /////////////////////////
            }


            _entities.Configuration.AutoDetectChangesEnabled = true;
            Save();
        }
 public List <Software> GetAllAssets()
 {
     return(context.Set <Software>().AsEnumerable()?.ToList());
 }
 public async Task <T> GetByIdAsync(int id)
 {
     return(await _context.Set <T>().FindAsync(id));
 }
Esempio n. 4
0
 public List <Book> GetAllAssets()
 {
     return(context.Set <Book>().AsEnumerable()?.ToList());
 }
Esempio n. 5
0
 protected BaseRepository(AssetContext ctx)
 {
     _ctx       = ctx;
     _entitySet = ctx.Set <T>();
 }