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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:38:11+00:00 2026-06-10T09:38:11+00:00

I am trying to implement a custom task scheduler system. I have a following

  • 0

I am trying to implement a custom task scheduler system.
I have a following (simplified) entity model:

class User
{
    public virtual long UserId { get; set; }
    public virtual string Name { get; set; }
}

class Task
{
    public virtual long TaskId { get; set; }
    public virtual long? UserId { get; set; }
    public virtual string TaskName { get; set; }
    public virtual Guid SchedulerSessionUid { get; set; }
}

For now, corresponding SQL tables are straight forward with fields mapping exactly as they appear in the classes above.

The scheduler is a C# Windows console app. It will run once per day.
It should work in a following way (simplified):

  1. generate a Guid for current session
  2. try selecting next User entity, which does not already have a task scheduled in the current scheduler session (Guid compare); if no such a User found, go to the step 5.
  3. add a new Task for the user selected in the step 2.
  4. go to step 2.
  5. exit the application

It seems a pretty trivial problem, but I have a problem implementing the second step. I have tried various queries, but there are some rules which always stop me.

Here are some rules which I have to obey while implementing the step 1:

  • I am not allowed to modify the User class or User SQL table
  • I may modify Task class and table, if it will help to solve the problem
  • I may add a new table or a stored procedure, if it will help
  • I have to implement it in a way which is as compatible with NHibernate and LINQ as possible
  • there might exist also some tasks which are not associated with any User object (the scheduler will ignore those, but still I have to keep that in mind while designing the SQL/LINQ query and NHibernate mapping).

Here are some real world example how it should work.

Users
-----------------
UserId    Name
-----------------
1         First
2         Second


Tasks
--------------------------------------------------------
TaskId    UserId    SchedulerSessionUid 
--------------------------------------------------------
1         NULL      6d8e48d0-4e92-477e-82fa-cd957e7dc201    
2         1         d213cfc8-23d6-49fb-b4e3-9ff3b60af6c4
3         1         9ee042df-88a7-447e-adbd-e7551ed50ae5

1.Now when the Scheduler runs, it generates a current session id = 76ea57fa-8c89-4c05-9ca2-a450b1f8a032.

  1. Now it should issue the magical LINQ query to NHibernate LINQ
    provider to get a User entity
  2. In the first iteration the query should return the User entity with
    UserId=1 because there are no tasks in the current session for that
    User yet
  3. Now the Scheduler creates a new task with UserId=1,
    SchedulerSessionUid=76ea57fa-8c89-4c05-9ca2-a450b1f8a032.

In the next iteration the Scheduler should get a User with UserId=2. Again, a new task is inserted with UserId=2, SchedulerSessionUid=76ea57fa-8c89-4c05-9ca2-a450b1f8a03.
In the next iteration the Scheduler should get no users, so it exits.

What LINQ query could I use to get the User for the step 2? What changes in my SQL schema and entity model do I need?

  • 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-10T09:38:13+00:00Added an answer on June 10, 2026 at 9:38 am

    If I now follow you correctly, you need to get a (just one) user for which there are no tasks with the given session id. Am I correct?

    Users.Where(u => !Tasks.Any(t = > t.UserId == u.UserId && t.SchedulerSessionUid == curSession)).FirstOrDefault()
    

    Edit:

    Since you’re doing several spins through this, would you perhaps be faster doing:

    foreach(var user toDealWith Users.Where(u => !Tasks.Any(t = > t.UserId == u.UserId && t.SchedulerSessionUid == curSession)))
    {
      //do stuff
    }
    

    Rather than keep hitting the database each time?

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

Sidebar

Related Questions

I'm trying to implement my custom authorize attribute like: public class MyCustomAuth : AuthorizeAttribute
I have a following problem. I'm trying to implement a model for my QTreeView
I am trying to implement a custom profile class in C# that inherits System.Web.Profile.ProfileBase.
I'm trying to implement some custom model metadata in ASP.NET MVC 3. I can't
I'm trying to implement a custom validation annotation in Seam. We have a list
I am trying to implement a custom control using a RowClickableGridView class provided on
I'm trying to implement custom suggestions for qsb. I have added CREATE TABLE IF
I got an assignment where I have to implement a custom call forwarding system
I'm trying to implement a custom class for dataannotations that retrieves error messages from
I am trying to implement a custom titlebar: Here is my Helper class: import

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.