Hi folks with a newbe doubt that I will thank, you could clarify me.
This is the context,
I'm in chapter 4 of "Programming EF 2nd ed". on section "Navigating to an EntityReference."
Typing, compiling and trying to understand the code:
var addresses = from a in context.Addresses
where a.CountryRegion == "UK"
select new { a,
a.Contact.FirstName,
a.Contact.LastName };
foreach (var address in addresses)
{
Console.WriteLine("{0} {1} {2} {3}", address.FirstName, address.LastName, address.a.Street1, address.a.City);
}
Although it perfectly compiles and run, the thing that I still don´t get is why it is possible that the compiler can allow me to get directly a.FirstName and a.LastName properties?, Overall taking into account that when we got the "addresses" variable via the query, the "structure" that gets defined is set of: a (an address) + a.Contact.FirstName (aka, the FirstName property attached or linked to the Contact navigation property of the a address) + a.Contact.LastName (aka, the LastName property attached or linked to the Contact navigation property of the a address).
I mean, in my understanding if I want to get the FirstName or LastName properties I should use Contact navigation property in the foreach cycle:
foreach (var address in addresses)
{
Console.WriteLine("{0} {1} {2} {3}", address.Contact.FirstName, address.Contact.LastName, address.a.Street1, address.a.City);
}
Does the supposition/assumptions I´m doing are correct?
Any clarification will be very helpfull.
Best Regards












