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

  • Home
  • SEARCH
  • 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 6084193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:29:33+00:00 2026-05-23T11:29:33+00:00

i have a 3 class models with overlapping relationships: class worder { int workerID

  • 0

i have a 3 class models with overlapping relationships:

class worder {
  int workerID
}    
class shift {
  int shiftID,
  int workerID,
  ICollection tasks //tasks for this shift and this worker
}
class task {
  int workerID
  int shiftID
}    

how do i populate a collection of shift objects that include its respective .tasks? something like:

var q = from shift in db.shifts
  .Include(s => s.tasks.Where(t=>t.shiftID == s.shiftID && t.workerID = s.workerID))

EDIT

I have successfully used an projection to create an anonymous type as suggested by jethro. but i would like to return strongly typed shift classes instead. is that possible? or a poor design of the shift model?

  • 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-23T11:29:33+00:00Added an answer on May 23, 2026 at 11:29 am

    You can join the tables.

    var joinedTables = from c in db.shifts
                       join p in db.tasks on c.ShiftID equals p.ShiftID & c.WorkerID equals p.WorkerID
    select new {Shifts = c, Tasks = p };
    

    Please check this Link for additional examples on Linq Joins.

    var shifts = db.shifts;
    var tasks = db.tasks;
    
    foreach(var shift in shifts)
    {
        var shiftID = shift.ShiftID;
        var workerID = shift.WorkerID;
        shift.tasks = tasks.Where(p=>p.shiftID == shiftID & p.WorkerID == workerID);
    }
    

    Something about the above feels “not right” to me, I think it would be best if you look at your design again, the tasks of the shifts should be populated automatically when you pull the shifts.

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

Sidebar

Related Questions

I have a models A and B , that are like this: class A(models.Model):
I have this class class Category(models.Model): title = models.CharField(max_length=60) created = models.DateTimeField() def __unicode__(self):
I have this model: class Auth(models.Model): TYPES = ( ('agent', 'Agent'), ('broker', 'Broker'), )
I have this model: class UserProfile(models.Model): (UserProfile description) user = models.ForeignKey(User) image = models.ImageField(upload_to=upload_to)
I have this models: class Balanta(models.Model): data = models.DateField() class Conturi(models.Model): cont=models.PositiveIntegerField() cont_debit=models.DecimalField(default=0, max_digits=30,
In one model, I have this: class MyModel(models.Model): relations = models.ManyToManyField(OtherModel) .... and if
I have class Cab(models.Model): name = models.CharField( max_length=20 ) descr = models.CharField( max_length=2000 )
I have three models: class ReleaseItem < ActiveRecord::Base has_many :pack_release_items has_one :pack, :through =>
I have models (simplified example): class Group(models.Model): name = models.CharField(max_length = 32) class Person(models.Model):
I have a following model: class Car(models.Model): make = models.CharField(max_length=40) mileage_limit = models.IntegerField() mileage

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.