Пример #1
0
 public void Add(T entity)
 {
     var ctx = new InventarisierungsloesungDB();
     {
         try
         {
             ctx.Set <T>().Add(entity);
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             MessageBox.Show("Es konnte keine Verbindung zur Datenbank hergestellt werden: " + e.Message);
         }
     }
 }
 public override void Update(customer entity)
 {
     var ctx = new InventarisierungsloesungDB();
     {
         try
         {
             var toUpdate = ctx.customers.Find(entity.customer_id);
             ctx.customers.Attach(toUpdate);
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             MessageBox.Show("Es konnte keine Verbindung zur Datenbank hergestellt werden: " + e.Message);
         }
     }
 }
Пример #3
0
        public long Count(Expression <Func <T, bool> > whereClause)
        {
            IQueryable <T> entities = Enumerable.Empty <T>().AsQueryable();
            var            ctx      = new InventarisierungsloesungDB();

            {
                try
                {
                    entities = ctx.Set <T>().Where <T>(whereClause);
                }
                catch (Exception e)
                {
                    MessageBox.Show("Es konnte keine Verbindung zur Datenbank hergestellt werden: " + e.Message);
                }
            }
            return(entities.Count());
        }
Пример #4
0
        public T GetSingle <P>(P pkValue)
        {
            var foundRowToEntityKey = new T();
            var ctx = new InventarisierungsloesungDB();

            {
                try
                {
                    foundRowToEntityKey = (from e in ctx.Set <T>() where e.Equals(pkValue) select e).FirstOrDefault();
                }
                catch (Exception e)
                {
                    MessageBox.Show("Es konnte keine Verbindung zur Datenbank hergestellt werden: " + e.Message);
                }
            }
            return(foundRowToEntityKey);
        }
Пример #5
0
        public IQueryable <T> GetAll()
        {
            IQueryable <T> entities = Enumerable.Empty <T>().AsQueryable();

            var ctx = new InventarisierungsloesungDB();

            {
                try
                {
                    entities = ctx.Set <T>();
                }
                catch (Exception e)
                {
                    MessageBox.Show("Es konnte keine Verbindung zur Datenbank hergestellt werden: " + e.Message);
                }
            }
            return(entities);
        }
        public override void Delete(location entity)
        {
            var ctx = new InventarisierungsloesungDB();

            {
                try
                {
                    var toDelete = ctx.locations.Find(entity.location_id);
                    ctx.locations.Remove(toDelete);
                    ctx.SaveChanges();
                }
                catch (Exception e)
                {
                    MessageBox.Show("Es konnte keine Verbindung zur Datenbank hergestellt werden: " + e.Message);
                }
            }
            ctx.Dispose();
        }
        public List <location> GetLocationsWithCte()
        {
            var ctx           = new InventarisierungsloesungDB();
            var locationsList = new List <location>();
            {
                try
                {
                    var result = ctx.cte_locations();

                    foreach (location loc in result)
                    {
                        locationsList.Add(loc);
                    }
                }

                catch (Exception e)
                {
                    MessageBox.Show("Es konnte keine Verbindung zur Datenbank hergestellt werden: " + e.Message);
                }
                ctx.Dispose();
                return(locationsList);
            }
        }