开发者

Calling a stored proc from Entity framework n times

开发者 https://www.devze.com 2023-02-15 08:25 出处:网络
I\'ve got a stored proc on a database which I need to call n number of times from within Entity Framework.

I've got a stored proc on a database which I need to call n number of times from within Entity Framework.

    public Points GetResults(Share share, DateTime startDate, DateTime endDate)
    {
        using (var ctx = new MyDatabaseEntities())
        {
            int? stockId = GetID(share, endDate);
            var data = ctx.GetData(stockId, 123, startDate, endDate, -23, 14, 3);
            var selectedPoints = data.Where(a => a.Date.HasValue && a.Value.HasValue).ToDictionary(a => a.Date.Value, a => a.Value.Value);
            return new Points(selectedPoints);
        }
    }

I have to call this for n number of shares (500 shares, 500 calls).开发者_StackOverflow I'm finding it to be a bit of a performance bottleneck for me at the moment. There is a lot of logic in the stored proc which I can't move out of the proc. Does anyone have any tips to speed this up? Or am I just buggered because I need to call this procedure n number of times?


If the stored procedure only takes one StockId and you need the result for many then you have no choice but to call it 500 times, this is always going to be slow.

Really you'd need to look at modifying the SP, I'd suggest looking at table-valued parameters depending on the database engine in use.

0

精彩评论

暂无评论...
验证码 换一张
取 消