14 Şubat 2018 Çarşamba

What is LazyLoading & EagerLoading in Entity Framework / LazyLoading Nedir

using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace UnivApp.Models { public class Student { public int Id { get; set; } public string LastName { get; set; } public string FirstMidName { get; set; } public DateTime EnrollmentDate { get; set; } public virtual ICollection<Enrollment> Enrollments { get; set; } /* About querying a student from database, all of the data will be retrieved when it is needed. (In other words, you are using lazy loading in here. You did not specify eager loading for the Courses navigation property (public virtual ICollection<Enrollment> Enrollments), it means the enrollments were not retrieved in the same query that got the students.Instead, when you try to access the Enrollments navigation property, a new query will be sent to the database to retrieve the data you want. Navigasyon Property için LazyLoading kullandık. Yani bir sorguda student çektiğimizde; navigasyon property'sinde bulunan veriler otomatik olarak gelmez. Şayet sen özellikle navigasyon property'deki bir değeri sorgu ile çekmek istersen; işte o zaman çekilir. Bu duruma Lazyloading denir (adı üstünde: Tembel Yükleme). Bu durumda, student'i çektikten sonra, bir de navigasyon Property'leri çekmek istersek şayet; bu durumda ikinci bir sorgu gönderilir. Lakin eğer EagerLoading kullansaydık; sorguda student'i çektiğimiz vakit; navigasyon property'lerine ait datalar da hep birlikte gelmiş olurdu. */ } }

Hiç yorum yok:

Yorum Gönder