Home > Net >  EF lambda match array of many conditions querying the database
EF lambda match array of many conditions querying the database

Time:04-09

For example, I have a list of testList
Public class testList
{
Public string name {get; The set; }
Public string code {get; The set; }
}

I want to go to the database to find and match the name and code line
Written
The db. The where (m=& gt; TestList. The contains (new {m.n ame, m.c ode}))
Or
The db. The where (m=& gt; TestList. Any (any)=& gt; Any. Name==m.n ame& & Any. Code==m.c ode))
EF will be thrown cannot translate exceptions

I now is
Var queryList=db. The where (m=& gt; M. estList. Select (s=& gt; S.n ame). The contains (ame) & amp; & M. estList. Select (s=& gt; S.c ode). The contains (m.c ode)) toList ();
Var result=queryList. Where (m=& gt; TestList. The contains (new {m.n ame, m.c ode}))
Twice in the screening, the feeling is very low efficiency

Want to have a query on the database should be how to write

CodePudding user response:

Db. AsEnumerable (). The where (m=& gt; TestList. Any (any)=& gt; Any. Name==m.n ame& & Any. Code==m.c ode))
But the table data time will slow

CodePudding user response:


try this?The db. The where (m=& gt; TestList. Select (p=& gt; P.n ame + p.c ode). The Contains (ame + m.c ode))

CodePudding user response:

reference 1st floor Logerlink response:
the AsEnumerable () where (m=& gt; TestList. Any (any)=& gt; Any. Name==m.n ame& & Any. Code==m.c ode))
But table data long will slow

Itself is want to optimize the, if slow it must not,

CodePudding user response:

The
refer to death on the second floor of the loners response:

try this?The db. The where (m=& gt; TestList. Select (p=& gt; P.n ame + p.c ode). The Contains (ame + m.c ode))


Haven't tried, but this approach is not rigorous, a, ab and BC, c but not want to meet the conditions
  •  Tags:  
  • LINQ
  • Related