这是我的存储过程:
ALTER PROCEDURE [dbo].[GetFullPlanHistory]
@PlanId int
AS
BEGIN
SET NOCOUNT ON;
DECLARE @bal decimal(8,2)
SELECT @bal = q.TotalCostNett + q.TotalCostVAT
FROM Quote q
INNER JOIN [plan] p
ON p.quoteid = q.quoteid
WHERE p.planid = @PlanId;
WITH tab(srt, dat, typ, ref, paid, refd, bal, note) AS
(
SELECT 0 srt,
p.StartDate,
'Plan started',
CONVERT(varchar(20), p.planid),
0.00 Paid,
0.00 Refund,
q.TotalCostNett + q.TotalCostVAT Balance,
'Plan started'
FROM [plan] p
INNER JOIN quote q
ON q.quoteid = p.quoteid
WHERE p.planid = @PlanId
UNION ALL
SELECT 1 srt,
t.[when],
CASE
WHEN tt.ShortName = 'RCT'
AND t.Amount > 0.00
THEN 'Refund'
ELSE tt.LongName
END descr,
t.Reference,
CASE
WHEN t.Amount > 0.00
THEN 0.00
ELSE
CASE
WHEN tt.ShortName = 'PRO'
THEN t.Amount * 1.2
ELSE t.Amount
END
END Paid,
CASE
WHEN t.Amount < 0.00
THEN 0.00
ELSE
CASE
WHEN tt.ShortName = 'PRO'
THEN t.Amount * 1.2
ELSE t.Amount
END
END Refund,
0.00 Balance,
t.Note
FROM Trans t
INNER JOIN TransactionType tt
ON tt.TransactionTypeId = t.TransactionTypeId
WHERE t.planid=@PlanId
AND tt.ShortName IN ('RCT', 'REF', 'TRI', 'TRO', 'PRO')
)
SELECT ROW_NUMBER() OVER (ORDER BY srt, dat) item, *
INTO #pbtemp
FROM tab
SELECT CONVERT(date,dat) [Date],
typ [Type],
CASE ABS(paid)
WHEN 0.00
THEN ''
ELSE CONVERT(varchar(20),ABS(Paid))
END Paid,
CASE ABS(refd)
WHEN 0.00
THEN ''
ELSE CONVERT(varchar(20),ABS(refd))
END Refund,
(
SELECT @bal + SUM(pb2.paid + pb2.refd)
FROM #pbtemp pb2
WHERE pb2.item <= pb.item
) Balance,
srt
FROM #pbtemp pb
UNION ALL
SELECT ISNULL(qs.ServiceDate, DATEADD(MONTH, qs.AgeMonths, p.StartDate)) [Date],
qs.Description [Type],
'' Paid,
'' Refund,
(
SELECT @bal + SUM(pb2.paid + pb2.refd)
FROM #pbtemp pb2
WHERE pb2.[dat] <= ISNULL(qs.ServiceDate, DATEADD(MONTH, qs.AgeMonths, p.StartDate))
) Balance,
1 srt
FROM [Plan] p
INNER JOIN QuoteSchedule qs
ON qs.QuoteId = p.QuoteId
WHERE p.PlanId = @PlanId
AND qs.Completed = 1
ORDER BY srt,Date;
DROP TABLE #pbtemp
END
当我使用Entity Framework将其定义导入我的MVC项目时,EF自动生成的函数如下所示:
public virtual int GetFullPlanHistory(Nullable<int> planId)
{
var planIdParameter = planId.HasValue ?
new ObjectParameter("PlanId", planId) :
new ObjectParameter("PlanId", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("GetFullPlanHistory", planIdParameter);
}
由于某种原因,即使过程返回结果集,也希望返回int
类型。
如何说服EF导入正确的定义?