Search code examples
c#linqapiasmx

Sorting Stored Procedure Results using Linq from another method


Is there some way where I could get the results that I want? All I see is that it just keeps on passing the values from another but the linq code is not working. I'm quite new to C# so I'm not used to it yet. Sorry.

    public List<BranchCinemaScheduleSelectStartEndTime> GetMoviesBranchCinemas(DateTime startTime, DateTime endTime,int branchKey)
    {


       List<XScheduleFromDate> GetRecords = new List<XScheduleFromDate>();
       List<BranchCinemaScheduleSelectStartEndTime> branchSchedule = new List<BranchCinemaScheduleSelectStartEndTime>();

        // getting the results of my stored procedure
      GetRecords = XML_GetMoviesFromBranch(startTime, endTime, branchKey);

       // trying to linq but it's not working
       IEnumerable query = from bs in GetRecords.ToList()
                           where bs.Cinemas == "Cinema 1"
                           select bs;

Solution

  • You will have to execute the query to get the result like below or You can just filter the records using below code. It will return the records in which Cinemas == "Cinema 1"

      var filteredRecords = (from bs in GetRecords
                           where bs.Cinemas == "Cinema 1"
                           select bs).ToList();
    
                                OR 
      var filteredRecords = GetRecords.Where(r=>r.Cinemas == "Cinema 1").ToList();