:
private struct UnpackedAndPacked
{
public string Unpacked {get;set;}
public string Packed {get;set;}
}
var ws = from w in query.Split()
where !String.IsNullOrWhiteSpace(w)
select new UnpackedAndPacked
{
Unpacked=w,
Packed=PhoneNumber.Pack(w)
};
:
where ws.All(w =>
c.FirstName == w.Unpacked
|| c.LastName == w.Unpacked
|| c.EmailAddress == w.Unpacked
|| c.HomePhone == w.Packed
|| c.CellPhone == w.Packed)
select c;
, , . , - ws.All SQL ws. , .
, , . , , , . LINQ . :
. . , AdventureWorks2008R2, , . ; :
public static IQueryable<Person> SearchCustomers(
AdventureWorksEntities entities, string nameQuery, string phoneQuery)
{
var wsu = from w in nameQuery.Split()
where !String.IsNullOrWhiteSpace(w)
select w;
var wsp = from w in phoneQuery.Split()
where !String.IsNullOrWhiteSpace(w)
select Pack(w);
return
entities.People.Where(
c => wsu.All(w => c.FirstName == w || c.LastName == w)).
Union(
entities.People.Where(
c =>
wsp.All(
w =>
c.PersonPhones.Any(p => p.PhoneNumber == w) ||
c.EmailAddresses.Any(a => a.EmailAddress1 == w))));
}
, :
IQueryable<Person> query = SearchCustomers(entities, "w1 w2",
"(602) (408)");
var oc = (ObjectQuery<Person>) query;
Console.WriteLine(oc.ToTraceString());