Entity framework generated for me such entities in my database:
public partial class Permission { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public Permission() { this.UserPermissions = new HashSet<UserPermission>(); this.ActionTypes = new HashSet<ActionType>(); } public int Permission_id { get; set; } public string Name { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection<UserPermission> UserPermissions { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection<ActionType> ActionTypes { get; set; } } public partial class UserPermission { public int UserPermission_id { get; set; } public int User_id { get; set; } public int Permission_id { get; set; } public int Give_User_id { get; set; } public Nullable<int> Remove_User_id { get; set; } public Nullable<System.DateTime> DateDel { get; set; } public System.DateTime DateAdded { get; set; } public virtual Permission Permission { get; set; } public virtual User User { get; set; } } public partial class ActionType { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public ActionType() { this.Queues = new HashSet<Queue>(); this.UserChangeHistories = new HashSet<UserChangeHistory>(); this.Permissions = new HashSet<Permission>(); } public int Action_id { get; set; } public string Name { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection<Queue> Queues { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection<UserChangeHistory> UserChangeHistories { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection<Permission> Permissions { get; set; } }
In the database, it looks like this:
Accordingly, I want to know if a particular User_id has permissions on a specific Action_id or not.
I tried this:
var result = from t1 in db.UserPermissions join t2 in db.Permissions on t1.Permission equals t2 join t3 in db.ActionTypes on t2.ActionTypes equals t3 select new { f1 = t2.Permission_id };
But he didn’t please the last join ...
ActionTypes
is anActionTypes
ICollection<ActionType>
, that is, a collection ofActionType
objects associated with one particularPermission
. And from this point of view,join t3 in db.ActionTypes on t2.ActionTypes equals t3
means "merge with theActionTypes
table where all the entries in this table are equal to theActionTypes
set of theActionTypes
object", which is pretty crazy :) - Anton Papin