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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:59:40+00:00 2026-05-12T22:59:40+00:00

Definitely a LINQ newbie, but very experienced with SQL and C# and wondering if

  • 0

Definitely a LINQ newbie, but very experienced with SQL and C# and wondering if this is possible in LINQ. If so, I could use it other places, but I figured this would be a good starting point (and help to simplify/clean up some code). This could be more generalized, but I figured this might be a good real-life example that could help explain.

Quick background: I’m doing a personal learning project building a scheduler and learning Spring.NET/DI, Fluent NHibernate, Quartz.NET, and trying to get my feat wet with TDD. Learned a ton so far.

A Quartz.NET IScheduler object has these property(1)/methods(2) (assume public)…

string[] JobGroupNames { get; }
string[] GetJobNames(string groupName)
Trigger[] GetTriggersOfJob(string jobName, string groupName)

Assume Trigger definition is just…

class Trigger
{  
    string Name { get; }
}  

I have a class I’m trying to get a list of which has a constructor like the following (because it’s immutable once created)…

class QuartzJob
{
    public QuartzJob(Guid groupId, Guid jobId, IEnumerable<string> triggerNames)
}

Currently this is how I’m handling it…

public IEnumerable<QuartzJob> GetQuartzInfo(IScheduler scheduler)
{
    List<QuartzJob> list = new List<QuartzJob>();

    foreach (string grp in scheduler.JobGroupNames)
    {
        foreach (string job in scheduler.GetJobNames(grp))
        {
            var triggerNames = scheduler
                .GetTriggersOfJob(job, grp)
                .ToList()
                .ConvertAll(t => t.Name);

            var qj = new QuartzJob(new Guid(grp), new Guid(job), triggerNames);
            list.Add(qj);
        }
    }    
    return list;
}

This way works fine (albeit maybe a little slow and complex), but those double foreach loops bug me and since I’m a “learn LINQ” kick, I thought this would a good chance and attempt to apply it.

Not asking for someone to write the code for me, as this is a learning project (although you are more then welcome to), just trying to see if LINQ can do things like this, and if so, looking for some more information on it… Method calls with query values, and use those values to build another query. If so, it would reduce some of my multiple foreach loops I have in other places in my code.

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-12T22:59:40+00:00Added an answer on May 12, 2026 at 10:59 pm

    The key to doing this in LINQ is to understand that .Select is your friend–but a surly friend who might hit you. I kid. You can use Select and it’s cousin SelectMany to transform your arrays on the fly.

    public IEnumerable<QuartzJob> GetQuartzInfo(IScheduler scheduler)
    {
        IEnumerable<QuartzJob> jobs = scheduler.JobGroupNames.SelectMany(   // Using SelectMany because there is an IEnumerable<QuartzJob> for each group and we want to flatten that.
            groupName => scheduler.GetJobNames(groupName).Select(  // Returns an IEnumerable<QuartzJob> for each group name found.
                jobName => 
                    // We're doing a lot in this new but essentially it creates a new QuartzJob for each jobName/groupName combo
                    new QuartzJob(new Guid(groupName), new Guid(jobName),
                        scheduler.GetTriggersOfJob(jobName, groupName).Select(trigger => trigger.Name)  // This transforms the GetTriggersOfJob into an IEnumerable<string> for use in the constructor of QuartzJob
                        ))); 
        return new List<QuartzJob>(jobs);
    }
    

    Or, if you prefer the inline query language it’d be a bit more readable and look like this:

    public IEnumerable<QuartzJob> GetQuartzInfo(IScheduler scheduler)
    {
        IEnumerable<QuartzJob> jobs = from groupName in scheduler.JobGroupNames
                                      from jobName in scheduler.GetJobNames(groupName) // stacking the two froms is the equivalent of SelectMany because the first select is defaulted as the result of the second.
                                      select new QuartzJob(new Guid(groupName), new Guid(jobName),
                                          // this sub-select is to get just the IEnumerable<string> of trigger names needed for the constructor.
                                          (from trigger in scheduler.GetTriggersOfJob(jobName, groupName)
                                           select trigger.Name));
        return new List<QuartzJob>(jobs);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's my first LINQ TO SQL Project , So definitely my question could be
I was wondering whether anyone knows definitively if LINQ to SQL has the capability
Okay this is definitely a n00b question but here goes. The way I understand
This seems weird: [SQL FIDDLE] The two users are definitely different i.e 1<>2. So
This is probably something silly I'm missing but I'm definitely lost. I'm using .NET
I definitely know that you can't send a message to other users, but is
This is definitely a bit of a noob question, but my searches so afar
I'm definitely still learning Javascript so please forgive me if this is a very
Is it definitely a good practice to use it? What are some possible situations
This is definitely subjective, but I'd like to try to avoid it becoming argumentative.

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.