开发者

How efficient is it to call a UDF and sproc from within my LINQ to SQL?

I ran into an issue where I need to call a UDF within my LINQ to SQL and then another stored procedure within that. Here's the code.

    public IQueryable<DataDTO> GetLotsaData(string dataId, DateTime date, string custIDs)
    {
        var data = (from rs in _context.spXI_GetData(dataId, date, custIDs)
                          select new DataDTO
                          {
                              Time = rs.Time,
                              TimeZone = _context.GetTimezone(postDate, _context.GetDetailedData(rs.PKID, custIDs).FirstOrDefault().Zip),
                              CompletedTime = rs.Completed_Time,
                          });

        return data.AsQueryable<DataDTO>();
    }

The line I'm worried about is the one where I'm calling the GetTimezone UDF. Is it inefficient to call a UDF in the middle of a LINQ query and then another stored procedure (GetDetailedData) to get a single value for that UDF? What kind of SQL would this generate?

It looks a bit convoluted to me, but still better than the alternative which would be a sub-select or join in my stored procedure. (I'm trying to avoid having my stored procedure return the new field - TimeZone - instead just having it returned in my DTO.) And yes, I realize this could all be avoide开发者_运维知识库d if we were using UTC. Sadly, I have no control over that.


Why can't spXI_GetData return the complete result set? I'd say that would be optimal in this situation.


The GetTimezone and GetDetailedData functions will be called for every row in the spXI_GetData set. Would be better if the GetTimezone function could return a inline table and than you could join with it instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜