Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting same data table after LINQ query
Message
De
10/06/2014 17:30:16
 
 
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01601612
Message ID:
01601620
Vues:
31
This message has been marked as a message which has helped to the initial question of the thread.
>>>Hi everybody,
>>>
>>>I have 2 data tables dtInstructors and dtAllScheduled. I need to limit dtInstructors to only those that have corresponding rows in AllScheduled with Layer =1 and Flag = true.
>>>
>>>In Visual FoxPro this is done with the following query:
>>>
>>>
>>>IF empty(m.lcRequest)
>>>          SELECT * FROM b_instr1 b WHERE exists ;
>>>          (SELECT 1 FROM csrAllSched s WHERE s.resource1 = b.instr_id and s.layer = 1 and s.schdassign = .t.) ;
>>>          ORDER BY instr_id INTO CURSOR b_instr readwrite
>>>      ELSE
>>>         SELECT * FROM b_instr1 b WHERE exists ;
>>>          (SELECT 1 FROM csrAllSched s WHERE s.resource1 = b.instr_id and s.layer = 1 and s.schdassign = .t.) ;
>>>         UNION ; 
>>>         SELECT * FROM b_instr1 WHERE ALLTRIM(instr_id) == m.lcRequest ;  
>>>         ORDER BY instr_id INTO CURSOR b_instr readwrite
>>>      endif
>>>
>>>In my case I need to do a similar kind of query with LINQ and get back dtInstructors again. Do you know how this can be done?
>>>
>>>Thanks a lot in advance.
>>
>>Exists becomes Any (http://msdn.microsoft.com/en-us/library/vstudio/bb534972%28v=vs.100%29.aspx).
>>Union is still Union (http://msdn.microsoft.com/en-us/library/vstudio/bb358407%28v=vs.100%29.aspx).
>
>I know that Exists becomes Any although in my case it's subquery and it's not exactly clear how to convert to any. My main problem is:
>
>var query = some linq query;
>
>How now I get back the dtInstructors from that query?
>
>Here is what I started from (not finished yet)
>
>
>   var query = from c in dtInstructors.AsEnumerable() 
>                                  where (from b in dtAllScheduled.AsEnumerable() where 1 == b.Field<Byte>("layer") 
>                                          && b.Field<   )
>
>based on http://www.telerik.com/forums/exists-query-in-dynamic-linq

Add "select c" at the end to select your datarow from dtInstructors. Use CopyToDataTable (http://msdn.microsoft.com/en-us/library/system.data.datatableextensions.copytodatatable%28v=vs.110%29.aspx) to put the results back into a datatable if there are any results.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform