I have a UserClasses, Screens and Workflow tables. The Workflow table is the association table between the UserClasses and Screens tables. Here are their structures…
UserClasses
- UserClassID (int PK)
- UserClass (string)
Screens
- ScreenID (int PK)
- ScreenName (string)
Workflow
- UserClassificationID
- ScreenID
I have the following data in the UserClasses table (Id and name):
- 1 UserClassification1
- 2 UserClassification2
- 3 UserClassification3
- 4 UserClassification4
- 5 UserClassification5
I have the following data in the Screens table (Id and name):
- 1 Screen1
- 2 Screen2
- 3 Screen3
I have the following data in the Workflow table (UserClassificationID and ScreenID):
1 1
1 2
By looking at the data Screen3 is not associated to a user classification. This is what I need, a list of all the screens that are not associated to a given user classification. How would I do this?
Additional information regarding my setup. The 2 classes that I have defined for the UserClasses and Screens tables:
public class UserClassification : IEntity
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Screen> Screens { get; set; }
}
public class Screen : IEntity
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<UserClassification> UserClassifications { get; set; }
}
Here are the configurations classes that is used in my database context class:
class ScreenConfiguration : EntityTypeConfiguration<Screen>]
{
internal ScreenConfiguration()
{
this.Property(x => x.Id).HasColumnName("ScreenID");
this.Property(x => x.Name).HasColumnName("ScreenName");
}
}
class UserClassificationConfiguration : EntityTypeConfiguration<UserClassification>
{
internal UserClassificationConfiguration()
{
this.ToTable("UserClasses");
this.Property(x => x.Id).HasColumnName("UserClassID");
this.Property(x => x.Name).HasColumnName("UserClass");
this.HasMany(i => i.Screens)
.WithMany(c => c.UserClassifications)
.Map(mc =>
{
mc.MapLeftKey("UserClassificationID");
mc.MapRightKey("ScreenID");
mc.ToTable("Workflow");
});
}
}
So given the above information I need to return a user classification object with a list of screens that are not associated to this user classification, in this case that would be a list of 1 screen item. How would I do something like this?
This is how I return a user classification object with a list of screens that are in the association table:
return DbContext.UserClasses
.Include("Screens")
.SingleOrDefault(x => x.Id == userClassificationId);
What about ?
hope this helps