Пример #1
0
        protected override void Seed(WebDocs.DataAccessLayer.WebDocsEntities context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
        }
Пример #2
0
        public virtual T GetSingle(Func <T, bool> where, params Expression <Func <T, object> >[] navigationProperties)
        {
            T item = null;

            using (var context = new WebDocsEntities())
            {
                IQueryable <T> dbQuery = context.Set <T>();

                //Apply eager loading
                foreach (Expression <Func <T, object> > navigationProperty in navigationProperties)
                {
                    dbQuery = dbQuery.Include <T, object>(navigationProperty);
                }

                item = dbQuery
                       .AsNoTracking()         //Don't track any changes for the selected item
                       .FirstOrDefault(where); //Apply where clause
            }
            return(item);
        }
Пример #3
0
        public virtual async Task <IList <T> > AsyncGetAll(params Expression <Func <T, object> >[] navigationProperties)
        {
            List <T> list;

            using (var context = new WebDocsEntities())
            {
                IQueryable <T> dbQuery = context.Set <T>();

                //Apply eager loading
                foreach (Expression <Func <T, object> > navigationProperty in navigationProperties)
                {
                    dbQuery = dbQuery.Include <T, object>(navigationProperty);
                }

                list = await dbQuery
                       .AsNoTracking()
                       .ToListAsync <T>();
            }
            return(list);
        }
Пример #4
0
        public virtual IList <T> GetList(Func <T, bool> where, params Expression <Func <T, object> >[] navigationProperties)
        {
            List <T> list;

            using (var context = new WebDocsEntities())
            {
                IQueryable <T> dbQuery = context.Set <T>();

                //Apply eager loading
                foreach (Expression <Func <T, object> > navigationProperty in navigationProperties)
                {
                    dbQuery = dbQuery.Include <T, object>(navigationProperty);
                }

                list = dbQuery
                       .AsNoTracking()
                       .Where(where)
                       .ToList <T>();
            }
            return(list);
        }
Пример #5
0
        public virtual CompletedTransactionResponses Update(params T[] items)
        {
            CompletedTransactionResponses CurrentResponse = new CompletedTransactionResponses()
            {
                Message         = "",
                TransActionType = TransactionType.Update,
                WasSuccessfull  = false
            };

            using (var context = new WebDocsEntities())
            {
                using (DbContextTransaction transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        DbSet <T> dbSet = context.Set <T>();
                        foreach (T item in items)
                        {
                            dbSet.Add(item);
                            foreach (DbEntityEntry <IEntity> entry in context.ChangeTracker.Entries <IEntity>())
                            {
                                IEntity entity = entry.Entity;
                                entry.State = GetEntityState(entity.EntityState);
                            }
                        }
                        context.SaveChanges();

                        transaction.Commit();
                        CurrentResponse.WasSuccessfull = true;
                        CurrentResponse.Message        = "Transaction Successfully Completed.";
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        CurrentResponse.Message = "Error occurred. - " + ex.Message;
                    }
                }
            }
            return(CurrentResponse);
        }