How do I do a sub-select in LINQ?
I am new to SQL server, please can any body help me out how to write this query in LINQ.
开发者_运维知识库SELECT [Plan_Num]
,(select top 1 ba_level_code + ' - ' + ba_level_desc from baLevel where ba_level_code = '0' + Level_Num) as [Level]
,(select top 1 cast(Column_Num as varchar) + ' - ' + Column_Description from baPlanColumnStructure where Column_Num = CL.Column_Num) as [Column]
,[Sort_Order]
FROM baCodeLibrary CL where code_id = 25468 and isactive = 1 order by [Plan_num]
Thanks
You are looking for something like this
var query = from cl in context.BaCodeLibrary
where cl.code_id == 25468 && cl.isactive == 1
orderby cl.Plan_num
select new
{
Level = (from ba in context.baLevel
where ba.ba_level_code == ("0" + ba.Level_Num)
select ba.ba_level_code + " - " + ba.ba_level_desc).Take(1),
Column = (from ba in context.baPlanColumnStructure
where ba.Column_Num == cl.Column_Num
select ba.ba_level_code + " - " + ba.ba_level_desc).Take(1),
Sort_Order = cl.Sort_Order
}
精彩评论