entity framework - Linq to Entities SQL Multiple LIKE statements -
I have to find an entity with some values, is empty I do not have to consider them, but I have other Linq To use a written statement using entities.
The result I want to achieve should be similar to this SQL,
... like WHERE (@taxid = '' or 'mtxid') @Texide + '%') and @ (@ PersonalLeader = '' or @PrashinLit @Dransaction + '%') and (@Certificate = '' or MC certificate @ certificate ''% '')
For my organizations my Linux looks like this:
person = reference. Where (E => E. Texi Content (TaxID) & amp; Amp; amp; Individual Personal Contact (Personal ID) & amp; amp; e.Certificate.Contains (Certificate) ToList ();
Any clues?
You can include parameter probes in the query
(Individual ID == "" || P. Individual Idi.Start (Individual ID)) & amp; Amp; (Certificate == "" || p.Certificate.Starts. (Certificate)) Select P
or make query dynamic
IQueryable & Lt; Person & gt; Query = context.person; If (taxId! = "") Query = query. Where (P = & gt; P. tax ID with start (tax ID)); If (Private ID! = "") Query = query. Where (P = & gt; P. Individuals with Startups (Personal ID)); If (certificate! = "") Query = query Where (p = & gt; p.Certificate.Starts with (certificate)); // etc var people = query.ToList ();
To consider whether the value of the parameter is, consider also to use it.
If you use LIKE '%' + @param + '%' code> then
start with
instead of in
.
Comments
Post a Comment