Click here to Skip to main content
15,512,456 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear all

This is my query in Ms SQL, and this works well. 


SQL
Select Id_per  From t011 Where id_reg = 22880 And id_cau NOT IN 
   (
      Select id_cau From t024 Where c_cau Like '%FIN%'  Or c_cau Like 
          '%PUB%' Or c_cau Like '%CHI%' 
   )


What I have tried:

Now I must convert in LinQ. This is the new query


C#
<pre>
    var query =

        (from r in t011 

         where r.id_reg == 22880 
		 
		  && ! (from c in t024 select c.id_cau).Contains(c.c_causale=='FIN' 
                 || c.c_causale=='PUB' || c.c_causale=='CHI')		 
		 
         select new
         {
             Id_per = r.id_per
         });


Why doesn't work ?? :-(
Posted
Updated 27-Sep-22 0:03am

1 solution

Because that's not the correct syntax for the Contains method.

Try:
C#
var subQuery = from c in t024
               where c.c_causale.Contains("FIN")
               || c.c_causale.Contains("PUB")
               || c.c_causale.Contains("CHI")
               select c.id_cau;

var query = from r in t011
            where r.id_reg == 22880
            && !subQuery.Contains(r.id_cau)
            select new
            {
                r.id_per
            };
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900