我们有一个现有的搜索工具,允许用户按地址和联系人姓名和电话号码搜索潜在客户表。有人向我们指出,它允许您按名字或姓氏搜索,但不能使用名字和姓氏进行搜索。
因此,如果有一个名为Dan Smith的联系人,搜索“Dan”将返回该行,搜索“Smith”,但搜索“Dan Smith”则不会。
这是原始代码:
var searchResults = from l in repo.GetAll()
from lc in l.LeadContacts
where
statuses.Contains(l.LeadStatusID) && (
l.Address != null && l.Address.Contains(Query) ||
l.Address2 != null && l.Address2.Contains(Query) ||
l.LotNumber != null && l.LotNumber.Contains(Query) ||
l.City != null && l.City.Contains(Query) ||
l.Zip != null && l.Zip.Contains(Query) ||
lc.Contact.FirstName != null && lc.Contact.FirstName.Contains(Query) ||
lc.Contact.LastName != null && lc.Contact.LastName.Contains(Query) ||
lc.Contact.Phone != null && lc.Contact.Phone.Contains(Query)
);
我认为这会有效,但它会引发错误:
无法创建“System.Char”类型的常量值。在此上下文中仅支持原始类型或枚举类型。
var searchResults = from l in repo.GetAll()
from lc in l.LeadContacts
let seller = lc.Contact.FirstName + ' ' + lc.Contact.LastName
where
statuses.Contains(l.LeadStatusID) && (
l.Address != null && l.Address.Contains(Query) ||
l.Address2 != null && l.Address2.Contains(Query) ||
l.LotNumber != null && l.LotNumber.Contains(Query) ||
l.City != null && l.City.Contains(Query) ||
l.Zip != null && l.Zip.Contains(Query) ||
lc.Contact.FirstName != null && lc.Contact.FirstName.Contains(Query) ||
lc.Contact.LastName != null && lc.Contact.LastName.Contains(Query) ||
seller != null && seller.Contains(Query) ||
lc.Contact.Phone != null && lc.Contact.Phone.Contains(Query)
);