コード例 #1
0
 public void Dispose()
 {
     if (dbContext != null)
     {
         dbContext.Dispose();
     }
 }
コード例 #2
0
        public IList <T> CreateBulk <T>(IList <T> t) where T : class, IDomainObject
        {
            using (TransactionScope scope = new TransactionScope())
            {
                PatientsMgtEntities context  = null;
                IList <T>           newBatch = new List <T>();
                try
                {
                    context = new PatientsMgtEntities();
                    context.Configuration.AutoDetectChangesEnabled = false;

                    int count = 0;
                    foreach (var entityToInsert in t)
                    {
                        ++count;

                        if (entityToInsert is IAuditObject)
                        {
                            (entityToInsert as IAuditObject).CreatedDate = DateTime.Now;
                        }

                        T newEntry = context.Set <T>().Add(entityToInsert);
                        newBatch.Add(newEntry);
                    }

                    context.SaveChanges();
                }
                finally
                {
                    if (context != null)
                    {
                        context.Dispose();
                    }
                }

                scope.Complete();

                return(newBatch);
            }
        }