© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
4 replies
crackTheCliff

❔ Route returning multiple of the same item.

So, I am trying to query multiple cases with the same name and for some reason it return the correct amount of cases but instead of them actually being the different cases it returns the correct number of cases but they are all the first case out of the list. If anyone can shed some light on this issue it would be greatly appreciated.
        // GET: api/SearchScreenViews/5
        [HttpGet("{id}")]
        public async Task<ActionResult<IEnumerable<SearchScreenView>>> GetSearchScreenView(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return NotFound();
            }

            DateTime.TryParse(id, out DateTime parsedDate); // Parse input string to DateTime

            var searchScreenViews = await _context.SearchScreens
                .Where(p =>
                    (p.LastName != null && p.LastName.Contains(id)) ||
                    (p.FirstName != null && p.FirstName.Contains(id)) ||
                    (p.CitationNumber != null && p.CitationNumber.Contains(id)) ||
                    (p.PkCaseId.ToString() == id) ||
                    (p.CourtDatetime != null && EF.Functions.DateDiffDay(p.CourtDatetime, parsedDate) == 0) || // Compare CourtDatetime as DateTime
                    (p.ViolationDate != null && EF.Functions.DateDiffDay(p.ViolationDate, parsedDate) == 0)) // Compare ViolationDate as DateTime
                .ToListAsync();

            Console.WriteLine(_context.SearchScreens.Where(p =>
                (p.LastName != null && p.LastName.Contains(id)) ||
                (p.FirstName != null && p.FirstName.Contains(id)) ||
                (p.CitationNumber != null && p.CitationNumber.Contains(id)) ||
                (p.PkCaseId.ToString() == id) ||
                (p.CourtDatetime != null && EF.Functions.DateDiffDay(p.CourtDatetime, parsedDate) == 0) || // Compare CourtDatetime as DateTime
                (p.ViolationDate != null && EF.Functions.DateDiffDay(p.ViolationDate, parsedDate) == 0))
                .GroupBy(p => p.PkCaseId)
                .ToQueryString());

            if (searchScreenViews == null || searchScreenViews.Count == 0)
            {
                return NotFound();
            }

            return searchScreenViews;
        }
        // GET: api/SearchScreenViews/5
        [HttpGet("{id}")]
        public async Task<ActionResult<IEnumerable<SearchScreenView>>> GetSearchScreenView(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return NotFound();
            }

            DateTime.TryParse(id, out DateTime parsedDate); // Parse input string to DateTime

            var searchScreenViews = await _context.SearchScreens
                .Where(p =>
                    (p.LastName != null && p.LastName.Contains(id)) ||
                    (p.FirstName != null && p.FirstName.Contains(id)) ||
                    (p.CitationNumber != null && p.CitationNumber.Contains(id)) ||
                    (p.PkCaseId.ToString() == id) ||
                    (p.CourtDatetime != null && EF.Functions.DateDiffDay(p.CourtDatetime, parsedDate) == 0) || // Compare CourtDatetime as DateTime
                    (p.ViolationDate != null && EF.Functions.DateDiffDay(p.ViolationDate, parsedDate) == 0)) // Compare ViolationDate as DateTime
                .ToListAsync();

            Console.WriteLine(_context.SearchScreens.Where(p =>
                (p.LastName != null && p.LastName.Contains(id)) ||
                (p.FirstName != null && p.FirstName.Contains(id)) ||
                (p.CitationNumber != null && p.CitationNumber.Contains(id)) ||
                (p.PkCaseId.ToString() == id) ||
                (p.CourtDatetime != null && EF.Functions.DateDiffDay(p.CourtDatetime, parsedDate) == 0) || // Compare CourtDatetime as DateTime
                (p.ViolationDate != null && EF.Functions.DateDiffDay(p.ViolationDate, parsedDate) == 0))
                .GroupBy(p => p.PkCaseId)
                .ToQueryString());

            if (searchScreenViews == null || searchScreenViews.Count == 0)
            {
                return NotFound();
            }

            return searchScreenViews;
        }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Inject multiple implementations of the same interface
C#CC# / help
4mo ago
❔ WPF Use of multiple item controls
C#CC# / help
4y ago
Reorder itemscontrol without resetting the item
C#CC# / help
3mo ago
WPF: Binding selected item of ComboBox inside ItemsControl
C#CC# / help
15mo ago