Hello all,
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!