将union all和Subquery SQL查询转换为LINQ

时间:2016-05-23 06:41:07

标签: sql-server linq c#-4.0 linq-to-sql

有关将我的下面的SQL转换为linq查询的任何帮助吗?

SELECT *
FROM BaseCategory
WHERE
    Id = (SELECT ParentId FROM BaseCategory WHERE Id = 10)
UNION ALL
SELECT *
FROM BaseCategory
WHERE
    ParentId = (SELECT ParentId FROM BaseCategory WHERE Id = 10)

1 个答案:

答案 0 :(得分:0)

你走了:

var query = (from c in db.BaseCategory 
            where c.Id = (From c1 in db.BaseCategory 
                          where c1.Id == 10 select c1.ParentId) 
            select c)
            .Concat
            (from c in db.BaseCategory 
            where c.ParentId = (From c1 in db.BaseCategory 
                                where c1.Id == 10 select c1.ParentId) 
            select c)