我遇到了一个必须将存储过程转换为LINQ查询的任务。
模特:
存储过程:
CREATE PROCEDURE [dbo].[sp_GetContactsForCompany]
(
@projectid AS UNIQUEIDENTIFIER
)
AS WITH recursion ( AccountId, Name, ParentAccountId )
AS (
SELECT AccountId, Name, ParentAccountId
FROM dbo.AccountBase
WHERE AccountId = @projectid
UNION ALL
SELECT a.AccountId, a.Name, a.ParentAccountId
FROM dbo.AccountBase AS a
INNER JOIN recursion AS b ON a.ParentAccountId = b.AccountId
)
SELECT ContactId, FullName
FROM dbo.ContactBase
WHERE ParentCustomerId IN (
SELECT AccountId
FROM recursion
)
ORDER BY FullName
LINQ:
from a in allAccs
where a.AccountId == id
select a;
这给了我所有具有给定id的帐户。但现在我不知道如何应用连接和递归。
任何提示都会很棒。
答案 0 :(得分:0)
您必须使用AsHierarchy()方法。
查看此文章:http://www.scip.be/index.php?Page=ArticlesNET18#AsHierarchy