开发者

How can i use unioan and nested from linq?

How can i convert to sql to linq . i don't understand nest开发者_运维百科ed select query. i need linq codes. Please help me:((((

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

LINQ:

  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();

if i write above codes error below:

How can i use unioan and nested from linq?


will that suit your needs?

var id = 
  (from task in stock.CTasks select new { task.id, task.workorder, jobseqno= task.jobseqno } )
  .Union(from card in stock.NonRoutineCards select new { card.id, card.workorderno, jobseqno = card.cardno })
  .Union(from card in stock.AdditionalWorkCards select new { card.id, card.workorderno, jobseqno = card.cardno })
  .Where(x => x.workorderno.TrimEnd() == ToNo && x.jobseqno == ToSeq)
  .FirstOrDefault();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜