Ejemplo n.º 1
0
 public List <Product> GetByUnitPrice(decimal min, decimal max)
 {
     using (EtradeContext context = new EtradeContext())
     {
         return(context.Products.Where(p => p.UnitPrice >= min && p.UnitPrice <= max).ToList());
     }
 }
Ejemplo n.º 2
0
 public List <Product> GetByUnitPrice(decimal price)
 {
     using (EtradeContext context = new EtradeContext())
     {
         return(context.Products.Where(p => p.UnitPrice >= price).ToList());
     }
 }
Ejemplo n.º 3
0
        public Product GetById(int id)
        {
            ///<summary>
            /// List all the values in database
            /// </summary>

            using (EtradeContext context = new EtradeContext())
            {
                //var query =
                //    from prod in context.Products
                //    where prod.Id == id
                //    select prod;
                //var result = query.FirstOrDefault();

                //var result = context.Products
                //    .Where(p => p.Id == id)
                //    .FirstOrDefault();   // results null if data is not exist

                // single and happy :D
                var result = context.Products
                             .Where(p => p.Id == id)
                             .SingleOrDefault(); // throws exception if there is more than one data

                return(result);
            }
        }
Ejemplo n.º 4
0
 public List <Product> GetAll()
 {
     using (EtradeContext context = new EtradeContext())
     {
         return(context.Products.ToList());
     }
 }
Ejemplo n.º 5
0
 public List <Product> GetByName(string key)
 {
     using (EtradeContext context = new EtradeContext())
     {
         return(context.Products.Where(p => p.Name.Contains(key)).ToList());
     }
 }
Ejemplo n.º 6
0
 public List <Product> GetByName(string key)
 {
     //EtradeContext bellekte çok yer kaplıyor. Bu tip nesneleri F12 ile giderse IDispsible yi görürüsün. using kullanırsan metoddan çıkınca gb yi beklemeden nesneyi zorla dispose edersin.
     using (EtradeContext context = new EtradeContext())
     {
         return(context.Products.Where(p => p.Name.Contains(key)).ToList());
     }
 }
Ejemplo n.º 7
0
 public List <Product> GetByUnitPrice(decimal min, decimal max)
 {
     //EtradeContext bellekte çok yer kaplıyor. Bu tip nesneleri F12 ile giderse IDispsible yi görürüsün. using kullanırsan metoddan çıkınca gb yi beklemeden nesneyi zorla dispose edersin.
     using (EtradeContext context = new EtradeContext())
     {
         return(context.Products.Where(p => p.UnitPrice >= min && p.UnitPrice <= max).ToList());
     }
 }
Ejemplo n.º 8
0
 public Product GetById(int id)
 {
     using (EtradeContext context = new EtradeContext())
     {
         var result = context.Products.FirstOrDefault(p => p.Id == id);
         return(result);
     }
 }
Ejemplo n.º 9
0
 public void Delete(Product product)
 {
     using (EtradeContext context = new EtradeContext())
     {
         var entity = context.Entry(product);
         entity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Ejemplo n.º 10
0
 public void Add(Product product)
 {
     using (EtradeContext context = new EtradeContext())
     {
         //Entity Framework'de Ekleme İşlemi
         context.Products.Add(product);
         context.SaveChanges();
     }
 }
Ejemplo n.º 11
0
 public Product GetById(int id)
 {
     //EtradeContext bellekte çok yer kaplıyor. Bu tip nesneleri F12 ile giderse IDispsible yi görürüsün. using kullanırsan metoddan çıkınca gb yi beklemeden nesneyi zorla dispose edersin.
     using (EtradeContext context = new EtradeContext())
     {
         var result = context.Products.FirstOrDefault(x => x.Id == id);
         return(result);
     }
 }
Ejemplo n.º 12
0
 public List <Product> GetByUnitPrice(decimal price)
 {
     //using : Blok bittiği anda nesneyi zorla bellekten atar
     //Metod bitmeden bellekten temizler
     using (EtradeContext context = new EtradeContext())
     {
         //Veri Tabanına SQL sorgusunu Atıyor
         return(context.Products.Where(p => p.UnitPrice >= price).ToList());
     }
 }
Ejemplo n.º 13
0
 public void Add(Product product)
 {
     using (EtradeContext context = new EtradeContext())
     {
         //context.Products.Add(product);
         var entity = context.Entry(product);
         entity.State = EntityState.Added;
         context.SaveChanges();
     }
 }
Ejemplo n.º 14
0
 public List <Product> GetAll()
 {
     //using : Blok bittiği anda nesneyi zorla bellekten atar
     //Metod bitmeden bellekten temizler
     using (EtradeContext context = new EtradeContext())
     {
         //Entity Framework'de veri tabanındaki Tabloya Erişim
         return(context.Products.ToList());
     }
 }
Ejemplo n.º 15
0
        public List <Product> GetAll()
        {
            ///<summary>
            /// List all the values in database
            /// </summary>

            using (EtradeContext context = new EtradeContext())
            {
                return(context.Products.ToList());
            }
        }
Ejemplo n.º 16
0
 public void Delete(Product product)
 {
     using (EtradeContext context = new EtradeContext())
     {
         //context.Products.Remove(product); silmeyi add gibi basit şekilde yapabiliriz.
         //gönderdiğimiz product nesnesini veritabanı ile eşleştiriyor. ama yanlış gibi
         var entity = context.Entry(product);
         entity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Ejemplo n.º 17
0
 public List <Product> GetByName(string key)
 {
     //using : Blok bittiği anda nesneyi zorla bellekten atar
     //Metod bitmeden bellekten temizler
     using (EtradeContext context = new EtradeContext())
     {
         // Veritabanından Where koşulu atıyor
         // aranan isimlerdeki nesneleri listeliyor
         //Harf duyarlılığını kaldırmak için Name ve Anahtar değerlerini ToLower ile küçültebiliriz.
         return(context.Products.Where(p => p.Name.ToLower().Contains(key.ToLower())).ToList());
     }
 }
Ejemplo n.º 18
0
        public void Update(Product product)
        {
            using (EtradeContext context = new EtradeContext())
            {
                //gönderdiğimiz product nesnesini veritabanı ile eşleştiriyor.
                var entity = context.Entry(product);
                entity.State = EntityState.Modified;

                context.SaveChanges();


                //update in ise olması gereken nesneyi çekersin çektiğin objede değişiklik yapıp savechanges yaparsın
            }
        }
Ejemplo n.º 19
0
        public void Add(Product product)
        {
            using (EtradeContext context = new EtradeContext())
            {
                var entity = context.Entry(product);
                entity.State = EntityState.Added;//böylede bir yazım olabilir
                context.SaveChanges();


                //kısa add işlemi
                //  context.Products.Add(product);
                //  context.SaveChanges();
            }
        }
Ejemplo n.º 20
0
        // Sadece 1 eleman getireceği için Liste Döndürmez !!!
        public Product GetById(int id)
        {
            //using : Blok bittiği anda nesneyi zorla bellekten atar
            //Metod bitmeden bellekten temizler
            using (EtradeContext context = new EtradeContext())
            {
                //Veri Tabanına SQL sorgusunu Atıyor
                //Sadece 1 eleman çekmek için FirstOrDefault

                //SingleOrDefault 1 den fazla aynı türden Kayıt Var ise
                // Hata VEriyor
                var result = context.Products.FirstOrDefault(p => p.Id == id);
                return(result);
            }
        }
Ejemplo n.º 21
0
        public List <Product> GetByUnitPrice(decimal maxPrice, decimal minPrice = 0M)
        {
            ///<summary>
            /// Most EFFICIENT-WAY
            /// MOST preferred WAY
            /// Direct query to SQL server
            /// </summary>

            using (EtradeContext context = new EtradeContext())
            {
                var query =
                    from prod in context.Products
                    where prod.UnitPrice >= minPrice && prod.UnitPrice <= maxPrice
                    select prod;
                var result = query.ToList();

                return(result);
            }
        }
Ejemplo n.º 22
0
        public List <Product> GetByKey(string key)
        {
            ///<summary>
            /// Most EFFICIENT-WAY
            /// MOST preferred WAY
            /// Direct query to SQL server
            /// </summary>

            using (EtradeContext context = new EtradeContext())
            {
                var query =
                    from prod in context.Products
                    where prod.Name.Contains(key)
                    select prod;
                var result = query.ToList();

                return(result);
            }
        }