tags:

views:

20

answers:

0

I am using Linq to SQL and have created a series of repositories to wrap table operations. The data context has been wrapped as well so that we can control when a data context is created / destroyed (since we are working in ASP .Net we are using one context per request). We have a number of scalar functions that return 4 character codes denoting various states of the data.

Where I'm having trouble is the sql generated is making 2 separate calls when using these 4 character codes as part of a where clause. The first fetches the 4 character code and the second performs the actual query. I would prefer that the two calls were done together.

A typical call that we are making looks like this.

Return From match In GetByStaff(staffId, sort) _
       Where match.SeasonCode = season _
             And match.MatchType = Context.cmtAcademy() _
             And match.MatchDateTime <= DateTime.Now.Date.AddDays(1) _
             And Not match.Cancelled _
       Select match

What I am trying to get is one sql call with the scalar function called inline.