我正在使用Entity Framework Reverse POCO Generator 2.19.0来处理现有数据库
一切都很好,直到我添加一个从多个表(包括时间表)执行SELECT的sproc,我希望工具(POCO Generator)生成一个Entity来存储来自该sproc的返回值,但它只是生成一个函数返回Int而不是预期的对象。
我应该如何构建sproc或poco生成器期望的SELECT类型?
这是程序
CREATE PROCEDURE [dbo].[GetAccountStatement] --Historial de transacciones
@MembershipID BIGINT
, @pagina INT = 1
, @npag INT = 100
AS
DECLARE @sql NVARCHAR(MAX),
@offset INT,
@NumeroTransacciones BIGINT,
@AccountID BIGINT
SELECT
@offset = (@pagina - 1) * @npag
SET FMTONLY OFF
SELECT
transactionCheck_Rel.CheckID,
AmountTotal AS Accrual,
0 AS Redemption INTO #TransactionAux_t4
FROM transactionCheck_Rel
JOIN [transaction]
ON [transaction].TransactionID = transactionCheck_Rel.TransactionID
AND TransactionTypeID = 4
SELECT
transactionCheck_Rel.CheckID,
0 AS Accrual,
AmountTotal AS Redemption INTO #TransactionAux_t3
FROM transactionCheck_Rel
JOIN [transaction]
ON [transaction].TransactionID = transactionCheck_Rel.TransactionID
AND TransactionTypeID = 3
SELECT
#TransactionAux_t4.CheckID,
#TransactionAux_t4.Accrual,
ISNULL(#TransactionAux_t3.redemption, 0) AS redemption INTO #TransactionAux
FROM #TransactionAux_t4
LEFT JOIN #TransactionAux_t3
ON #TransactionAux_t3.CheckID = #TransactionAux_t4.CheckID
ORDER BY #TransactionAux_t4.CheckID
INSERT INTO #TransactionAux
SELECT
#TransactionAux_t3.CheckID,
#TransactionAux_t3.Accrual,
ISNULL(#TransactionAux_t3.redemption, 0) AS redemption
FROM #TransactionAux_t3
SELECT
#TransactionAux.CheckID,
[dbo].[check].StoreID,
store.SystemName,
dbo.[check].NetAmount,
account.AccountID,
#TransactionAux.Accrual,
#TransactionAux.redemption,
account.InitialBalance,
account.FinalBalance,
dbo.[transaction].TransactionID,
dbo.[transaction].BusinessDate,
dbo.membershipAccount_Rel.MembershipID
FROM dbo.account
LEFT JOIN dbo.assignCheck
ON assignCheck.AccountID = account.AccountID
LEFT JOIN [dbo].[check]
ON [check].CheckID = assignCheck.CheckID
LEFT JOIN #TransactionAux
ON #TransactionAux.CheckID = [check].CheckID
JOIN dbo.[transaction]
ON [transaction].AccountID = account.AccountID
JOIN dbo.transactionDetail
ON transactionDetail.TransactionID = [transaction].TransactionID
LEFT JOIN transactionCheck_Rel
ON transactionCheck_Rel.TransactionID = [transaction].TransactionID
LEFT JOIN dbo.store
ON store.StoreID = [check].StoreID
JOIN dbo.membershipAccount_Rel
ON membershipAccount_Rel.AccountID = account.AccountID
ORDER BY membershipAccount_Rel.MembershipID ASC OFFSET @offset ROWS FETCH NEXT @npag ROWS ONLY
答案 0 :(得分:2)
反向POCO生成器的作者Simon Hughes在discussion forum for the project中说明了对这个问题的回答。
问题:
“我在存储的PRoc中使用临时表。但是类不是 由于在SP“
中使用此临时表而生成
回答:
“发电机无法做任何事情。但你可以做的是 将存储过程更改为表值函数,和 定义要返回的表。我相信我最近提到过这个 某处并举了一个例子。“
我进一步浏览了讨论论坛,但尚未找到他所引用的例子。你可能最好直接在该论坛上提问。我以前曾在那里提过问题,西蒙非常敏感。
此SO post也可能有所帮助。