Example #1
0
 public List <S> Select <S>(Expression <Func <T, S> > selector)
 {
     using (ERPEntities entities = new ERPEntities())
     {
         return(entities.Set <T>().Select(selector).ToList());
     }
 }
Example #2
0
 public int GetCount()
 {
     using (ERPEntities entities = new ERPEntities())
     {
         return(entities.Set <T>().Count());
     }
 }
Example #3
0
 public List <T> GetAll()
 {
     using (ERPEntities entities = new ERPEntities())
     {
         return(entities.Set <T>().ToList());
     }
 }
Example #4
0
        public void Insert(T entity)
        {
            using (ERPEntities entities = new ERPEntities())
            {
                try
                {
                    entities.Set <T>().Add(entity);
                    entities.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    Exception raise = e;
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        foreach (var ve in eve.ValidationErrors)
                        {
                            string message = string.Format("{0}:{1}",
                                                           eve.Entry.Entity.ToString(),
                                                           ve.ErrorMessage);

                            raise = new InvalidOperationException(message, raise);
                        }
                    }
                    throw raise;
                }
            }
        }
Example #5
0
        public void Setup()
        {
            ERPEntities context = new ERPEntities();

            // delete all books in DB
            var books = context.Set <Book>();

            context.Books.RemoveRange(books);

            // delete all deals in DB
            var deals = context.Set <Deal>();

            context.Deals.RemoveRange(deals);

            context.SaveChanges();
        }
Example #6
0
        public IList <T> Get <T>(IList <Condition> conditions) where T : ERPData
        {
            IQueryable <T> data = context.Set <T>();

            if (conditions != null)
            {
                foreach (Condition condition in conditions)
                {
                    PropertyInfo propertyInfo = typeof(T).GetProperty(condition.field);

                    ParameterExpression e = Expression.Parameter(typeof(T), "e");
                    MemberExpression    m = Expression.MakeMemberAccess(e, propertyInfo);
                    ConstantExpression  c = null;
                    switch (condition.valueType)
                    {
                    case ValType.DateTime:
                        c = Expression.Constant(DateTime.Parse(condition.value), typeof(DateTime));
                        break;

                    case ValType.Int:
                        c = Expression.Constant(int.Parse(condition.value), typeof(int));
                        break;

                    case ValType.String:
                        c = Expression.Constant(condition.value, typeof(string));
                        break;
                    }


                    BinaryExpression b = null;
                    switch (condition.op)
                    {
                    case Operator.EqualTo:
                        b = Expression.Equal(m, c);
                        break;

                    case Operator.GreaterThan:
                        b = Expression.GreaterThan(m, c);
                        break;
                    }

                    Expression <Func <T, bool> > lambda = Expression.Lambda <Func <T, bool> >(b, e);
                    data = data.Where(lambda);
                }
            }
            return(data.ToList());
        }
Example #7
0
 public void Insert(T entity)
 {
     using (ERPEntities entities = new ERPEntities())
     {
         entities.Set <T>().Add(entity);
         entities.SaveChanges();
     }
 }