为了显示一个页面,我需要从各种表格中获取大量信息,目前,加载页面大约需要20秒,这很糟糕。了解实体框架下的多个表格结果
因此,我想将所有内容都移动到一个存储过程中,并获取所有信息的旧DataTable方式。
我得到这个
public WinnerPageInformation FindWinnerPageInformation(int calendarId)
{
BackendPagesContext ctx = new BackendPagesContext(db.Connection);
IMultipleResults results = ctx.WinnersBackendPageInformation(calendarId);
return new WinnerPageInformation()
{
Challenges = results.GetResult<Challenges>(),
Content = results.GetResult<ContentWinners>().FirstOrDefault(),
Einfo = results.GetResult<ContentEmails>().FirstOrDefault(),
Fields = results.GetResult<SubscriberFields>(),
Prizes = results.GetResult<Prizes>(),
Winners = results.GetResult<Winners>()
};
}
和WinnersBackendPageInformation看起来像这样
public class BackendPagesContext : DataContext
{
public BackendPagesContext(System.Data.IDbConnection connection)
: base(connection) { }
[Function(Name = "dbo.sp_GetWinnersBackendPageInformation")]
[ResultType(typeof(JK_ContentWinners))]
[ResultType(typeof(JK_Winners))]
[ResultType(typeof(JK_SubscriberFields))]
[ResultType(typeof(JK_Prizes))]
[ResultType(typeof(JK_Challenges))]
[ResultType(typeof(JK_ContentEmails))]
public IMultipleResults WinnersBackendPageInformation(
[Parameter(Name = "calendarId", DbType = "Int")] int calendarId)
{
IExecuteResult result =
this.ExecuteMethodCall(this,
((MethodInfo)(MethodInfo.GetCurrentMethod())),
calendarId);
return (IMultipleResults)(result.ReturnValue);
}
}
public interface IMultipleResults : IFunctionResult, IDisposable
{
IEnumerable<TElement> GetResult<TElement>();
}
,但我现在面临的问题是,该行this.ExecuteMethodCall
抛出一个错误,指出该结果不是MultipleTable结果。
我的存储过程看起来像
ALTER PROCEDURE sp_GetWinnersBackendPageInformation
@calendarId numeric = 0
AS
BEGIN
SELECT * FROM ContentWinners WHERE calendar_id = @calendarId;
SELECT * FROM Winners WHERE calendar_id = @calendarId;
SELECT * FROM SubscriberFields WHERE calendar_id = @calendarId ORDER BY position;
SELECT * FROM Prizes WHERE calendar_id = @calendarId ORDER BY prizetype_id, to_day, title;
SELECT * FROM Challenges WHERE calendar_id = @calendarId;
SELECT * FROM ContentEmails WHERE calendar_id = @calendarId;
END
GO
错误消息
声明函数“WinnersBackendPageInformation”不返回IMultipleResults多个结果类型。
我错过了什么?
感谢您指出...从来没有得到该评论:( – balexandre 2010-12-22 04:23:55