100 likes | 466 Views
Lazy Loading vs. Eager Loading. Lazy Loading: Gerekeni, gerektiğinde getir. Eager Loading: Hepsini getir . Gerekenleri kullan. Lazy Loading vs. Eager Loading. Lazy Loading vs. Eager Loading. dbo.Categories. dbo.Suppliers. dbo.Products. SQL. SELECT * FROM Products p
E N D
Lazy Loading vs. Eager Loading • Lazy Loading: Gerekeni, gerektiğinde getir. • Eager Loading: Hepsini getir. Gerekenleri kullan.
dbo.Categories dbo.Suppliers dbo.Products
SQL SELECT* FROMProducts p INNERJOINCategories c ONp.CategoryID=c.CategoryID INNERJOIN Suppliers s ON p.SupplierID = s.SupplierID
Lazy Loading (EFFiltre.sln) privatevoid Form1_Load(object sender, EventArgs e) { NorthwindEntities db = newNorthwindEntities(); List<Product> urunler = db.Products.ToList(); //cmbKategoriler.DataSource = db.Categories.ToList(); ListViewDoldur(urunler); } privatevoid ListViewDoldur(List<Product> _gelenList) { NorthwindEntities db = newNorthwindEntities(); listViewUrunler.Items.Clear(); foreach (var item in _gelenList) { ListViewItem lw = newListViewItem(); lw.Text = item.ProductName; lw.SubItems.Add(item.Category.CategoryName); lw.SubItems.Add(item.UnitPrice.ToString()); lw.SubItems.Add(item.Supplier.CompanyName); lw.SubItems.Add(item.Supplier.City); listViewUrunler.Items.Add(lw); } } 151
Eager Loading privatevoidbtnSelect_Click(object sender, EventArgs e) { NorthwindEntities db = newNorthwindEntities(); listViewUrunAyrinti.Items.Clear(); List<UrunAyrinti> uList = db.Products.Select(x => newUrunAyrinti() { UrunAd = x.ProductName, KategoriAd = x.Category.CategoryName, Fiyat = x.UnitPrice, TedarikciAd = x.Supplier.CompanyName, TedarikciSehir = x.Supplier.City }).ToList(); foreach (var item in uList) { ListViewItem lw = newListViewItem(); lw.Text = item.UrunAd; lw.SubItems.Add(item.KategoriAd); lw.SubItems.Add(item.Fiyat.ToString()); lw.SubItems.Add(item.TedarikciAd); lw.SubItems.Add(item.TedarikciSehir); listViewUrunAyrinti.Items.Add(lw); }