gpt4 book ai didi

.net - Entity Framework (QueryBuilder) - where 子句 "it"前缀

转载 作者:行者123 更新时间:2023-12-05 01:31:32 25 4
gpt4 key购买 nike

我最近遇到了以下 Entity Framework 的语法。注意 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);
}

最佳答案

基于 this article , "it"将 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));

可能不完全像上面显示的那样,但它给出了一般的想法。

关于.net - Entity Framework (QueryBuilder) - where 子句 "it"前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9688598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com