Fire Scheduling with Triggers in CMMS I worked on cmms project .
I have some scheduling , esch of schedule have some triggers (e.g,. Bymeter , byActivity ,ByPeriod).

I wrote some methods to generate workOrder for each Schedule if schedule is ok.

public async Task&lt;IEnumerable&lt;TodayScheduleTaskViewModel&gt;&gt; GetTodayTasks(int page, int recordsPerPage = 50)
    {
        int resultForSkip = page * recordsPerPage;
        var _result = new List&lt;Schedule&gt;();

        bool repeat = true;
        do
        {
            var data = await GetExpression(page, recordsPerPage).Cacheable().ToListAsync();
            if (data.Count == 0) { repeat = false; break; };
            _result.AddRange(Calculate(data).ToList());
            page++;
        } while ((_result.Count &lt; recordsPerPage &amp;&amp; repeat));


        return _result.Select(row =&gt; new TodayScheduleTaskViewModel
        {
            //map fields 

        }).ToList();
    }


and :

 private IQueryable&lt;Schedule&gt; GetExpression(int page, int recordsPerPage = 50)
    {
        int resultForSkip = page * recordsPerPage;

        return _schedules.OrderBy(row =&gt; row.Code).Skip(() =&gt; resultForSkip).Take(() =&gt; recordsPerPage);
    }


and Calculate method :

 private IEnumerable&lt;Schedule&gt; Calculate(List&lt;Schedule&gt; schedules)
    {
        List&lt;Schedule&gt; result = new List&lt;Schedule&gt;();
        foreach (var schedule in schedules)
        {

            bool IsAllTriggersRequired = schedule.WhenFire == GenerateWorkOrderWhen.AllOfTheTriggersFire ? true : false;
            bool dontContinue = false;

            bool timeFalg = false, meterFlag = false, workFlag = false;
            int countersuccessTriggers = 0;


            foreach (var item in schedule.Triggers)
            {


                switch (item.TypeId)
                {


                    case TriggerType.ByWork:

                        if (dontContinue &amp;&amp; !IsAllTriggersRequired) break;
                        int workValue = _equipmentFunctionService.GetAssetWorkValue(schedule.AssetId.Value,schedule.CalculatingType);
                        if ((workValue &gt;= item.WorkValue) &amp;&amp; !dontContinue)
                        {
                            workFlag = true;
                            dontContinue = true;
                            countersuccessTriggers++;
                        };
                        break;
                }

            }
            var AllTriggersAvailabe = countersuccessTriggers == schedule.Triggers.Count &amp;&amp; IsAllTriggersRequired;
            var AnyTriggersAvailabe = timeFalg || meterFlag || workFlag;


            if (AllTriggersAvailabe || (!IsAllTriggersRequired &amp;&amp; AnyTriggersAvailabe))
                result.Add(schedule);
        }
        return result;
    }


let's describe method and my goal:

I want to speed up my query.

1- Why use do...While in GetTodayTask :
my GridView Page size is const and I want Just return same records, First I get some Records and pass them to Calculate() Method to check some condition and maybe in Calculate() Method some records removed  (result count changed in calculate())
Some notes on your coding style:


Why do you do int resultForSkip = page * recordsPerPage; at the start of GetTodayTasks? You never use this variable.
var _result = new List&lt;Schedule&gt;();: the underscore prefix should be used to indicate class-level fields, not variables inside a method. Why even call it _result, when schedules is far more clear?
data is also way too generic as a name.
GetExpression doesn't return an expression.
Why is the parameter of Calculate(List&lt;Schedule&gt; schedules) a List&lt;T&gt;? An IEnumerable&lt;T&gt; suffices.
Don't abbreviate "do not" to "don't" in variable names: dontContinue.
The "Falg" in timeFalg should be "Flag".
countersuccessTriggers is improperly capitalized, but it's also badly named. Perhaps successTriggerCount would be better.
There are several places where random blank lines appear. Please clean these.
Use descriptive names: foreach (var item in schedule.Triggers). Why call it an item when it is a trigger?
Why is the property called TypeId? Judging from the rest of the code it is an enum value, so why not call it Type?
Method scope variables should be camelCase, so IsAllTriggersRequired, AllTriggersAvailabe, AnyTriggersAvailabe are incorrect. 
Also pay attention to verb conjugations: IsAllTriggersRequired should be areAllTriggersRequired.
However, looking at IsAllTriggersRequired, AllTriggersAvailabe and AnyTriggersAvailabe there are more problems beyond those already mentioned: the naming is inconsistent and feels incorrect. Boolean names like "IsAvailabe" are great as property names, but don't work well as variable names. In this case I'd go for allTriggersAreRequired, allTriggersAreAvailabe and anyTriggerIsAvailabe.