Exemple #1
0
        public IHttpActionResult PostClass([FromBody] ClassRequest classRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var student = db.Students.FirstOrDefault(x => x.IndexNumber == classRequest.StudentId);

            var studentClass = new StudentClassesEntity
            {
                ClassId   = classRequest.ClassId,
                StudentId = student.Id
            };

            var ctx = new EfDbContext();

            try
            {
                ctx.ClassesEntities.Add(studentClass);
                ctx.SaveChanges();
            }
            catch (Exception e)
            {
                return(BadRequest(e.ToString()));
            }
            finally
            {
                ctx.Dispose();
            }
            return(CreatedAtRoute("DefaultApi", new { id = classRequest.StudentId }, classRequest));
        }
Exemple #2
0
        public bool SaveConferences(IEnumerable <Conference> conferences)
        {
            var i  = 0;
            var db = new EfDbContext();
            var sw = new Stopwatch();

            sw.Start();
            foreach (var conference in conferences)
            {
                db.Configuration.AutoDetectChangesEnabled = false;
                db.Configuration.ValidateOnSaveEnabled    = false;
                db.Conferences.Add(conference);
                i++;
                if (i % _batchSize == 0)
                {
                    db.SaveChanges();
                    db.Dispose();
                    db = new EfDbContext();
                }
            }
            db.SaveChanges();
            db.Dispose();
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds / 1000);
            return(true);
        }
Exemple #3
0
 public override void DisposeCore()
 {
     if (dataContext != null)
     {
         dataContext.Dispose();
     }
 }
Exemple #4
0
 public virtual void Dispose(bool disposing)
 {
     if (!_disposed && disposing)
     {
         Сontext.Dispose();
     }
     _disposed = true;
 }
Exemple #5
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Exemple #6
0
        public void Dispose()
        {
            if (_efbdcontext != null)
            {
                _efbdcontext.Dispose();
            }

            GC.SuppressFinalize(this);
        }
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             _context.Dispose();
         }
     }
     _disposed = true;
 }
Exemple #8
0
 /// <summary>
 /// Disposes all external resources.
 /// </summary>
 /// <param name="disposing">The dispose indicator.</param>
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_dbContext != null)
         {
             _dbContext.Dispose();
             _dbContext = null;
         }
     }
 }
Exemple #9
0
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing)
         {
             _dbContext.Dispose();//随工作单元销毁
         }
     }
     this.disposed = true;
 }
Exemple #10
0
 public virtual void Dispose(bool disposing)
 {
     if (this._disposed)
     {
         return;
     }
     if (disposing)
     {
         _db.Dispose();
     }
     this._disposed = true;
 }
Exemple #11
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    if (Repositories != null)
                    {
                        Repositories.Clear();
                    }

                    Context.Dispose();
                }
            }

            _disposed = true;
        }
Exemple #12
0
        public bool UpdateStructureSetAuthor(IEnumerable <KeyValuePair <string, string> > entries)
        {
            var i  = 0;
            var db = new EfDbContext();

            foreach (var entry in entries)
            {
                db.Configuration.AutoDetectChangesEnabled = true;
                db.Configuration.ValidateOnSaveEnabled    = true;

                var xelement = XElement.Parse(entry.Value);
                var authors  = xelement.ExtractAuthors();
                if (authors.Any())
                {
                    var publication = db.Publications.FirstOrDefault(t => t.Key == entry.Key);
                    if (publication != null)
                    {
                        publication.Authors.AddRange(authors.Select(k => new Author()
                        {
                            Name = k, Publication = publication
                        }));
                        i++;
                        if (i % _batchSize == 0)
                        {
                            db.SaveChanges();
                            db.Dispose();
                            db = new EfDbContext();
                        }
                        if (i % 100000 == 0)
                        {
                            Console.WriteLine("100K Done");
                        }
                    }
                }
            }


            db.SaveChanges();
            db.Dispose();
            return(true);
        }
Exemple #13
0
        public bool SaveBibTexEntries(IEnumerable <BibTexEntry> entries)
        {
            var i  = 0;
            var db = new EfDbContext();

            foreach (var entry in entries)
            {
                db.Configuration.AutoDetectChangesEnabled = false;
                db.Configuration.ValidateOnSaveEnabled    = false;
                db.BibTexEntries.Add(entry);
                i++;
                if (i % _batchSize == 0)
                {
                    db.SaveChanges();
                    db.Dispose();
                    db = new EfDbContext();
                }
            }

            db.SaveChanges();
            db.Dispose();
            return(true);
        }
Exemple #14
0
        public bool SaveConferencesWithAddedAuthors(IEnumerable <Conference> conferences, IEnumerable <KeyValuePair <string, string> > entries)
        {
            //Publicatione projezieren
            var sw1 = new Stopwatch();

            sw1.Start();
            var publicationsWithoutAuthors = new Dictionary <string, Publication>();

            foreach (var conference in conferences)
            {
                foreach (var @event in conference.Events)
                {
                    if (@event.Publications != null)
                    {
                        foreach (var publication in @event.Publications)
                        {
                            if (!publicationsWithoutAuthors.ContainsKey(publication.Key))
                            {
                                publicationsWithoutAuthors.Add(publication.Key, publication);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Keine Publicationen: " + @event.EventKey);
                    }
                }
            }
            sw1.Stop();
            Console.WriteLine("sw1 = " + (int)sw1.ElapsedMilliseconds / 1000);

            //Authors Updaten
            var sw2 = new Stopwatch();

            sw2.Start();
            Parallel.ForEach(entries, entry =>
            {
                Publication publication = new Publication();
                if (publicationsWithoutAuthors.ContainsKey(entry.Key))
                {
                    publication =
                        publicationsWithoutAuthors[entry.Key];
                    if (publication == null)
                    {
                        return;
                    }
                }

                var xelement = XElement.Parse(entry.Value);
                var authors  = xelement.ExtractAuthors();
                if (authors.Any())
                {
                    publication.Authors.AddRange(
                        authors.Select(k => new Author()
                    {
                        Name = k, Publication = publication
                    }));
                }
            });
            sw2.Stop();
            Console.WriteLine("sw2 = " + (int)sw2.ElapsedMilliseconds / 1000);

            //Context speichern

            var i   = 0;
            var db  = new EfDbContext();
            var sw3 = new Stopwatch();

            sw3.Start();
            foreach (var conference in conferences)
            {
                db.Configuration.AutoDetectChangesEnabled = false;
                db.Configuration.ValidateOnSaveEnabled    = false;
                db.Conferences.Add(conference);
                i++;
                if (i % _batchSize == 0)
                {
                    db.SaveChanges();
                    db.Dispose();
                    db = new EfDbContext();
                }
            }
            db.SaveChanges();
            db.Dispose();
            sw3.Stop();
            Console.WriteLine("sw3 = " + sw3.ElapsedMilliseconds / 1000);
            return(true);
        }
 public void Dispose()
 {
     _dbContext.Dispose();
 }
Exemple #16
0
 public void Dispose()
 {
     _context.Dispose();
 }
Exemple #17
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     _efContext?.Dispose();
 }
 protected override void Dispose(bool disposing)
 {
     dbContext.Dispose();
     base.Dispose(disposing);
 }
 protected override void Dispose(bool disposing)
 {
     _context.Dispose();
 }