public Product GetById(int id) { using (ETradeContext context = new ETradeContext()) {// first or default ilkini alır single or default 1 den fazla ise hata fırlatır var result = context.Products.SingleOrDefault(p => p.Id == id); return(result); } }
public void Add(Product product) { using (ETradeContext context = new ETradeContext()) { context.Products.Add(product); //context deki products a product ekle context.SaveChanges(); //veri tabanına yaz } }
public Product GetById(int id)//verilen id e gore product getirir { using (ETradeContext context = new ETradeContext()) { var result = context.Products.FirstOrDefault(p => p.Id == id);//FirstorDefault girilen id varsa product getirir yoksa null getirir return(result); } }
public List <Product> GetAll() { /*using kullanarak dispose işlemi yapılır garbage collector çalışır. Method bitince memory temizlenir.*/ using (ETradeContext context = new ETradeContext()) { return(context.Products.ToList()); } }
public void Add(Product product) { using (ETradeContext context = new ETradeContext()) { context.Products.Add(product); // içine verdiğimiz nesneyi ekliyor. context.SaveChanges(); // yaptığımız işlemleri commit ediyoruz. } }
public List <Product> GetByName(string key) { using (ETradeContext context = new ETradeContext()) { // bu işlemi veri tabanında yapmak daha hızlı sonuç verir. return(context.Products.Where(p => p.Name.Contains(key)).ToList()); } }
public List <Product> GetByUnitPrice(decimal price) { // Min max parametreleri arasında bulunan unitprice a sahip ürünleri döndürür. using (ETradeContext context = new ETradeContext()) { return(context.Products.Where(p => p.UnitPrice >= price).ToList()); } }
internal List <Product> GetByUnitPrice(decimal min, decimal max) //iki fiyat arası için filtreleme { using (ETradeContext context = new ETradeContext()) { return(context.Products.Where(p => p.UnitPrice >= min && p.UnitPrice <= max).ToList()); //burada veri tabanını sorgulayıp ürünleri filtreleyip iki fiyat arasındaki verileri almak için kod yazdık } }
internal List <Product> GetByUnitPrice(decimal price) //fiyat olarak aramak istersek { using (ETradeContext context = new ETradeContext()) { return(context.Products.Where(p => p.UnitPrice >= price).ToList()); //burada veri tabanını sorgulayıp ürünleri filtreleyip fiyat sorgulamak için bir kod yazdık } }
public Product GetById(int id) { using (ETradeContext context = new ETradeContext()) { return(context.Products.FirstOrDefault(p => p.Id == id)); //return context.Products.SingleOrDefault(p => p.Id == id); Eğer aynı değerde birden fazla veri bulursa hata fırlatır. } }
//App.Config içerisine sql bağlantımızı aldık. public List <Product> GetAll() { using (ETradeContext context = new ETradeContext() ) //ETradeContext pahalı bir nesne bu bağlamda method bittiği zaman bellekten atar GarbageCollector Dispose yapar direk!!! { return(context.Products.ToList()); //veritabanındaki tabloya erişip listeledik. } }
public List <Product> GetAll() { //Bu blok içerisinde context'i kullanır daha sonrasında bellekten atar. (Dispose eder.) using (ETradeContext context = new ETradeContext()) { return(context.Products.ToList()); } }
public List<Product> GetAll() { using (ETradeContext context = new ETradeContext()) { return context.Products.ToList(); } }
public List <Product> GetByUnitPrice(decimal min, decimal max) { using (ETradeContext context = new ETradeContext()) { //parametre olarak gelen key ile veri tabanındaki UnitPrice karşılaştırılır. min-max arasında yer alan veriler döndürülür. var result = context.Products.Where(p => p.UnitPrice >= min && p.UnitPrice <= max).ToList(); return(result); } }
public List <Product> GetByName(string key) { using (ETradeContext context = new ETradeContext()) { //parametre olarak gelen key veri tabanında sorgulanır ve eşleşen değerler geri döndürülür. var result = context.Products.Where(p => p.Name.Contains(key)).ToList(); return(result); } }
public List <Product> GetByUnitPrice(decimal price) { using (ETradeContext context = new ETradeContext()) { //parametre olarak gelen price ile veri tabanındaki UnitPrice karşılaştırılır. price a eşit veya daha yüksek veriler döndürülür. var result = context.Products.Where(p => p.UnitPrice >= price).ToList(); return(result); } }
public List <Product> GetByUnitPrice(decimal min, decimal max) { //Veri Tabanına erişme ve listeleme using (ETradeContext context = new ETradeContext()) { return(context.Products.Where(p => p.UnitPrice >= min && p.UnitPrice <= max).ToList()); } }
public List <Product> GetAll() { //Veri Tabanına erişme ve listeleme using (ETradeContext context = new ETradeContext()) { return(context.Products.ToList()); } }
public void Add(Product product) { using (ETradeContext context = new ETradeContext()) { context.Products.Add(product); context.SaveChanges(); } }
public List <Product> GetById(int id) { using (ETradeContext context = new ETradeContext()) { var result = context.Products.FirstOrDefault(p => p.Id == id); return(result); } }
public Product GetById(int id) { using (ETradeContext context = new ETradeContext()) { var result = context.Products.SingleOrDefault(p => p.Id == id); return(result); } }
public List <Product> GetName(string key) { using (ETradeContext context = new ETradeContext()) { //Burası veri tabanına Where ile sorgu atar. Sql de küçük büyük harf duyarlılığı yoktur. return(context.Products.Where(p => p.Name.Contains(key)).ToList()); } }
public Product GetById(int id) { using (ETradeContext context = new ETradeContext()) //Nesneyi zorla bellekten atarak garbage collector ı beklemeden boşaltır. { var result = context.Products.SingleOrDefault(p => p.Id == id); return(result); } }
public List <Product> GetByName(string key) { //Veri Tabanına erişme ve listeleme using (ETradeContext context = new ETradeContext()) { return(context.Products.Where(p => p.Name.Contains(key)).ToList()); } }
public void Add(Product product) { using (ETradeContext context = new ETradeContext()) { var entity = context.Entry(product); //oluşturulan var entity contextle bağlantı kurup gönderilen parametreyi karşılaştırılır. entity.State = System.Data.Entity.EntityState.Added; //EntityState de yer alan ekleme fonksiyonu çalıştırılır. context.SaveChanges(); //değişiklikler kaydedilir. } }
public Product GetById(int id) { //Veri Tabanına erişme ve listeleme using (ETradeContext context = new ETradeContext()) { var result = context.Products.FirstOrDefault(p => p.Id == id); return(result); } }
public void Update(Product product) { using (ETradeContext context = new ETradeContext()) { var entity = context.Entry(product); entity.State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public void Delete(Product product) { using (ETradeContext context = new ETradeContext()) { var entity = context.Entry(product); entity.State = System.Data.Entity.EntityState.Deleted;//EntityState de yer alan silme fonksiyonu çalıştırılır. context.SaveChanges(); } }
public void Delete(Product product) { using (ETradeContext context = new ETradeContext()) { var entity = context.Entry(product); entity.State = EntityState.Deleted; context.SaveChanges(); } }
public void Delete(Product product) { using (ETradeContext context = new ETradeContext()) { var entity = context.Entry(product); //contexte abone ol product için gönderdiğimiz productu veritabanındaki product ile eşitliyor entity.State = EntityState.Deleted; //id üzerinden eşitler primary key olduğu için context.SaveChanges(); } }