bug*_*ger 4 .net entity-framework where-clause
我最近遇到了以下Entity Framework的语法.注意where子句 -
.Where("it.LastName = @ln AND it.FirstName = @fn")
Run Code Online (Sandbox Code Playgroud)
怎么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);
}
Run Code Online (Sandbox Code Playgroud)
基于这篇文章,"它"将ObjectQuery称为引用参数的默认名称.通过使用ObjectQuery的Name属性,您实际上可以更改它,以便在您的where子句中可以将其引用为您希望的任何名称:
ObjectQuery<Contact> contactQuery;
contactQuery.Name = "contact";
contactQuery = context.Contacts
.Where("contact.LastName = @ln AND contact.FirstName = @fn",
new ObjectParameter("ln", lastName),
new ObjectParameter("fn", firstName));
Run Code Online (Sandbox Code Playgroud)
可能不完全像上面所示,但它给出了一般的想法.
| 归档时间: |
|
| 查看次数: |
1160 次 |
| 最近记录: |