title: How can i use unioan and nested from linq?
body: <p>How can i convert to sql to linq . i don't understand nested select query. i need linq codes.  Please help me:((((</p>
  
  <pre><code>SELECT @id=id FROM 
      (SELECT id,workorder AS workorderno ,CAST(jobseqno AS int) AS jobseqno FROM dbo.CTask
       UNION ALL
       SELECT id,workorderno,cardno AS jobseqno FROM dbo.NonRoutineCard
       UNION ALL
       SELECT id,workorderno,cardno AS jobseqno FROM dbo.AdditionalWorkCard) a
  WHERE RTRIM(workorderno)=RTRIM(@ToNo) AND jobseqno=@ToSeq
  </code></pre>
  
  <p><b>LINQ:</b></p>
  
  <pre><code>  var id = 
    (from task in stock.CTasks select new { task.id, task.workorder, task.jobseqno } )
    .Union(from card in stock.NonRoutineCards select new { card.id, card.workorderno, card.cardno })
    .Union(from card in stock.AdditionalWorkCards select new { card.id, card.workorderno, card.cardno })
    .Where(x => x.workorderno.TrimEnd() == ToNo && x.jobseqno == ToSeq)
    .FirstOrDefault();</code></pre>
  
  <p>if i write above codes error below: </p>
  
  <p><a href="https://i.stack.imgur.com/JWO3k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JWO3k.png" alt="alt text"></a>
  </p>