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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:29:51+00:00 2026-06-17T15:29:51+00:00

My Log class has 2 properties. List<LogDetails> string Title And my LogDetails class has

  • 0

My Log class has 2 properties.

List<LogDetails>
string Title

And my LogDetails class has 2 properties:

string Message
LogStatus LogStatus  //enum

During this objects life time, it receives many messages which are stored for logging at a later stage. The LogStatus Enum has a few states, but simply it is either “in progress”, “file not found error”, “success” or “failed”.

I am trying to use Linq to match only those which failed, but I can’t build the new type.

List<Log> filteredLogs = (from a in logs
                          from b in a.LogDetailsList
                          where b.Status == LogDetails.LogStatus.Failed
                          select new Log()
                                  {
                                     Title = a.Title,
                                     LogDetailsList = a.LogDetailsList
                                  }).Distinct().ToList();

My filteredLogs returns to me the full list as if the where clause hadn’t worked.

I tried

 List<Log> filteredLogs = (from a in logs
                           from b in a.LogDetailsList
                           where b.Status == LogDetails.LogStatus.Failed
                           select new Log()
                                  {
                                       Title = a.Title,
                                       LogDetailsList = new LogDetails() { Message = b.Message, Status = b.Status }
                                  }).Distinct().ToList();

This doesn’t work either as it appears I can’t call the ToList() method from within the Linq query.

EDIT

Does any one have any suggestions on how to overcome this issue? My goal is to have a List which only lists those which failed.

  • 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-17T15:29:53+00:00Added an answer on June 17, 2026 at 3:29 pm

    Use Enumerable.Any on your “nested” LogDetails list.

    List<Log> failedLogs = logs
                .Where(l => l.LogDetails.Any(ld => ld.LogStatus==LogStatus.Failed))
                .ToList();
    

    This returns all logs where at least one log-detail has LogStatus.Failed.

    Here’s a Demo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using android.util.Log class Foo { private void boo() { // This is the
I've created two entities (simplified) in C#: class Log { entries = new List<Entry>();
I have a Log class that has several static methods which help log information
I have an instance of a logging class logger, this class has a function
So my class has two different UIWebView objects (one is a menu the other
I have a Device class that I have defined that has 2 properties, LocalConnection
I have this tag in a php string: <input type=submit name=op id=edit-submit value=Log in
If I have a Customer class that just has simple properties (e.g. Name ,
I have associated models like this: class Batch has_many :logs class Log belongs_to :batch
I have a some class (Hello), this class has foo property and this property

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.