I recently came across following syntax of Entity Framework. Notice the where clause –
.Where("it.LastName = @ln AND it.FirstName = @fn")
What does it. do? And why it instead of Contacts.LastName? Any detailed information will be helpful. Thanks in advance.
string firstName = @"Frances";
string lastName = @"Adams";
using (AdventureWorksEntities context =
new AdventureWorksEntities())
{
// Get the contacts with the specified name.
ObjectQuery<Contact> contactQuery = context.Contacts
.Where("it.LastName = @ln AND it.FirstName = @fn",
new ObjectParameter("ln", lastName),
new ObjectParameter("fn", firstName));
// Iterate through the collection of Contact items.
foreach (Contact result in contactQuery)
Console.WriteLine("Last Name: {0}; First Name: {1}",
result.LastName, result.FirstName);
}
Based on this article, “it” refers to the ObjectQuery as a default name to be referencing parameters. By using the Name property of the ObjectQuery you can actually change it so that in your where clause it could be referenced as whatever name you wish it to be:
Probably not exactly like what is shown above, but it gives the general idea.