コード例 #1
0
 internal List <Product> GeyByUnitPrice(decimal minPrice, decimal maxPrice)
 {
     using (ETContext context = new ETContext())
     {
         return(context.Products.Where(p => p.UnitPrice >= minPrice && p.UnitPrice <= maxPrice).ToList());
     }
 }
コード例 #2
0
 internal List <Product> GetAll()
 {
     using (ETContext context = new ETContext()) // <using> sonunda bellekten gönder.
     {
         return(context.Products.ToList());
     }
 }
コード例 #3
0
 internal List <Product> GetByName(string key)
 {
     using (ETContext context = new ETContext())
     {
         return(context.Products.Where(p => p.Name.Contains(key)).ToList());
         // Products içeriğinde ara, her bir elemanın p.Name (isim) içeriyorsa (key) listesini al ve döndür.
     }
 }
コード例 #4
0
 internal void Update(Product product)
 {
     using (ETContext context = new ETContext())
     {
         var entity = context.Entry(product);
         entity.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #5
0
 internal void Delete(Product product)
 {
     using (ETContext context = new ETContext())
     {
         // context.Products.Remove(product);
         var entity = context.Entry(product);
         entity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
コード例 #6
0
 internal void Add(Product product)
 {
     using (ETContext context = new ETContext())
     {
         //context.Products.Add(product);
         var entity = context.Entry(product);
         entity.State = EntityState.Added;
         context.SaveChanges();
     }
 }
コード例 #7
0
        internal Product GetById(int id)
        {
            using (ETContext context = new ETContext())
            {
                return(context.Products.SingleOrDefault(p => p.Id == id)); // SinleOrDefault
                // Ürünleri incele verilen <id> göre kayıt al. (Birden fazla dönüş olursa hata verir)

                // return context.Products.FirstOrDefault(p => p.Id == id); // FirstOrDefault
                // Products <id> ile eşleşen ilk kayıtı alır, bulamazsa <null> döndürür.
            }
        }