Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3304772
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:05:51+00:00 2026-05-17T21:05:51+00:00

I am trying to formulate a LINQ query to select a sublist of a

  • 0

I am trying to formulate a LINQ query to select a sublist of a list where it meets a where condition like so:

List<Entities.Base> bases = this.GetAllBases();
List<Entities.Base> thebases = from aBase in bases
                               where aBase.OfficeCD == officeCD
                               select aBase;

where Base is just an Entity class:

public string BaseCD { get; set; }
        public string BaseName { get; set; }
        public string OfficeCD { get; set; }
        public DateTime EffectiveDate { get; set; }
        public DateTime ExpirationDate { get; set; }

I am getting an error “Cannot implictly convert type System.Collections.Generic.IEnumerable to System.Collections.Generic.List

So I tried to apply the Cast operator but that fails. I see now that I am not tring to convert the type of the element. How can I solve this issue? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:05:51+00:00Added an answer on May 17, 2026 at 9:05 pm

    This is not really a problem that can be solved by “casting”; the result of the query you’ve got isn’t a list – it’s a deferred-executing sequence that will stream the matching items out on demand. You will have to actually load these results into aList<T>to achieve your purpose. For example, the Enumerable.ToListmethod will create a new list, populate it with the results of the query and then return it.

    A few options:

    var thebases = (from aBase in bases
                    where aBase.OfficeCD == officeCD
                    select aBase).ToList();
    
    // fluent syntax
    var thebases = bases.Where(aBase => aBase.OfficeCD == officeCD)
                        .ToList();
    
    // not a LINQ method - an instance method on List<T>. 
    // Executes immediately - returns a List<T> rather than a lazy sequence
    var thebases = bases.FindAll(aBase => aBase.OfficeCD == officeCD);
    
    // "manual" ToList()
    var theBases = new List<Entities.Base>();
    var matchingBases =  from aBase in bases
                         where aBase.OfficeCD == officeCD
                         select aBase;
    
    foreach(var matchingBase in matchingBases)
       theBases.Add(matchingBase);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to formulate the right query to select records that each have a
I've been trying to formulate a query to help myself identify resource-heavy queries/database/users using
trying to use this jstl to formulate a json string, how can i make
I'm trying to use a for loop in order to formulate this: expand('*+123456') should
I've been trying to work out why this query asking for a manager and
I'm trying to formulate an SQL query for a messaging system that will return
I'm trying to formulate a query that will allow me to return all of
I'm trying to create a C# application that extracts data from pages like this
I am trying to formulate a selector to select a set of visible elements.
I am trying to parse formula in C# language like 5*3 + 2 (3*4

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.