>>>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-linqAdd "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.