Witam. Robie kurs asp.net i nie bardzo rozumiem tego zapisu
public ViewResult Index()
{
var customers = _context.Customers.Include(c=>c.MembershipType).ToList();//Eager loading
return View(customers);
}
public ActionResult Details(int id)
{
var customer = _context.Customers.Include(c=>c.MembershipType).SingleOrDefault(c => c.Id == id);
if (customer == null)
return HttpNotFound();
return View(customer);
}
Jest on w kontrolerze.
Model Customer
public class Customer
{
public int Id { get; set; }
[Required]
[StringLength(255)]
public string Name { get; set; }
public bool IsSubscribedToNewsLetter { get; set; }
public DateTime? /*Making nullable*/ BirthDate { get; set; }
public MembershipType MembershipType { get; set; }
public byte MembershipTypeId { get; set; }
}
Model MembershipType
public class MembershipType
{
public byte Id { get; set; }
public string Name { get; set; }
public short SignupFee { get; set; }
public byte DurationInMonths { get; set; }
public byte DiscountRate { get; set; }
}
Przede wszystkim nie rozumiem tego. Dlaczego includujemy jedynie membershipType, a nie includujemy nigdzie samych Customers? Czy po prostu jest to zaincludowane w 1 linii? Wiem ze jest tam chyba LINQ i to nie o niego mi chodzi
var customers = _context.Customers.Include(c=>c.MembershipType).ToList();//Eager loading
Jako ze najpierw ogarnalem jako tako php nie bardzo rozumiem jak tu dziala przesylanie danych. Jakby ktos mogl wyjasnic albo podeslac jakis link do wyjasnienia to bylbym wdzieczny,