我最近遇到下面的实体框架语法。注意where子句 -实体框架(QueryBuilder) - where子句“它”的前缀
.Where("it.LastName = @ln AND it.FirstName = @fn")
it.
是做什么用的?而为什么it
而不是Contacts.LastName?任何详细信息都会有帮助。提前致谢。
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);
}
我从来没有必要在'where'前面添加我的where子句。...... – c0deNinja 2012-03-13 17:11:28
什么版本的EF? – c0deNinja 2012-03-13 17:12:32
EF 4 - 这里是MSDN文章 - http://msdn.microsoft.com/en-us/library/bb896238.aspx – bugBurger 2012-03-13 19:49:10