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 8158189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:31:44+00:00 2026-06-06T17:31:44+00:00

I have two classes – MyBaseClass and BaseClassContainer – that are declared like such:

  • 0

I have two classes – MyBaseClass and BaseClassContainer – that are declared like such:

public class MyBaseClass
{
    private Guid id;
    public Guid ID
    {
        if (id == Guid.Empty)
        {
            id = Guid.NewGuid();
        }
        return id;
    }
    //...Other Properties omitted for brevity
}

and

public class BaseClassContainer : INotifyPropertyChanged
{
    private ObservableCollection<MyBaseClass> baseClasses;
    public ObservableCollection<MyBaseClass> BaseClasses
    {
    //...Omitted for brevity...
    }
}

Then in my code I have an ObservableCollection of type BaseClassContainer (BaseClassContainerCollection). What I’m trying to figure out is how can I use LINQ to select a single BaseClassContainer from the ObservableCollection where one of its MyBaseClass.ID matches a specific Guid. The reason I’m using the Single() method is because I know they’re all going to be unique.

I’ve tried the following but it doesn’t work:

var result = BaseClassContainerCollection.Single(container => container.BaseClasses.Single(baseClass => baseClass.ID == specificGuid));

I get an error saying: Cannot implicitly convert type ‘MyBaseClass’ to ‘bool’. What am I missing?

  • 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-06-06T17:31:45+00:00Added an answer on June 6, 2026 at 5:31 pm

    Lets break apart your query:

    BaseClassContainerCollection.Single(yourPredicate);
    

    Single, as it is used here, basically says “filter BaseClassContainerCollection on this predicate” (a “filter” function that evaluates to true or false for whether or not to include it in the results). Instead of a function that returns true/false, you’re saying you want it to evaluate to a MyBaseClass, which doesn’t make sense. Your inner call to Single makes sense, because x => x.Id == guid is a function that returns true/false and filters to only those elements that meet the criteria (then states that you know there will only be one of them in the results or else throw an exception).

    What you want to do is Select the single MyBaseClass result from the inner query, then call Single on the result (without a predicate) since you know the result should only have one item returned. I believe you’re looking for:

    BaseClassContainerCollection.Select(container => container.BaseClasses.Single(baseClass => baseClass.ID == specificGuid)).Single();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes declared like this: class Object1 { protected ulong guid; protected
I have two classes: public class Singleton{ private Singleton(){...} private static class InstanceHolder{ private
I have two classes class PopulationMember { public: void operationOnThisMember1(); void operationOnThisMember2(); ... private:
I have two classes defined like public class PostleitzahlList : ObservableCollection<Postleitzahl> { } public
I have two classes declared in C# code: public class A { public static
I have two classes, Foo and Bar, that have constructors like this: class Foo
I have two classes: public class Article { private ISet<IdentNumber> identNumbers = new HashedSet<IdentNumber>();
I have two classes public class PrepaidPackage { private String name; private String serviceClassID;
I have two classes Foo and Bar that Bar extends Foo as below: class
I have two classes, one that inherits from the other. The base class is

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.