EF 4.1存储过程的返回结果

时间:2015-02-13 11:16:10

标签: c# entity-framework entity-framework-4.1

我是EF新手,刚刚创建了一个新的存储过程来返回一些基本信息

CREATE PROCEDURE GetTop10Clients
   @AccountId NVARCHAR(50)
AS
BEGIN
    SET NOCOUNT ON;

    SELECT TOP 10  
        Client.Name, Count(Client.Name) AS Number
    FROM           
    WHERE        
        (Client.AccountId = @AccountId)
    GROUP BY 
        Client.Name
    ORDER BY 
        Number DESC
END
GO

然后我添加到我的edmx并创建了一个名为GetTop10Clients的函数导入,以返回复杂GetTop10Clients_Result(跟http://www.entityframeworktutorial.net/EntityFramework4.3/execute-stored-procedure-using-dbcontext.aspx

但我无法弄清楚如何称呼它

namespace ClientSystem.Repositories.Ef
{
    public class AccountRepository : IAccountRepository
    {
        public AccountRepository(ObjectSet<Account> set ,ObjectContext ctx) : base(ctx,set)
        {
        }

        public DashboardStats GetTop10Stats(string accountId)
        {
            //var results = GetTop10Clients(accountId); ??????
            return null;
        }
    }
}

感谢您的帮助,示例会很棒。

1 个答案:

答案 0 :(得分:0)

您将在objectcontext/dbcontext中生成一个函数,如下所示。

public virtual ObjectResult<GetTop10Clients_Result> GetTop10Clients(Nullable<int> accountId)
{
    .....
}

您可以像下面这样调用该方法。

using (var context = new ObjectContext())
{
    var clients = context.GetTop10Clients(1);
}