I am trying to show a related class that the EF code first automatically creates from many to many relationships as a separate object, because the related object needs to be referenced in other classes , however I seem to have a problem getting the data that exists in the database.
I have the following 3 objects:
public class Role : Entity
{
public virtual ICollection<User> Users { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public virtual ICollection<Permission> Permissions { get; set; }
}
public class User: Entity
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public virtual ICollection<Role> Roles { get; set; }
}
public class UserRole : Entity
{
public User User { get; set; }
public Role Role { get; set; }
}
This creates the following tables:

Now I see that the problem is that it creates the table RoleUserswhen it should not and should just use my table UserRoles. How to make the linked table be UserRolesso that I can link the related object in EF so that I can use it in other objects?
, , ? - User.Roles.Any(y = > y.Name == "blah" ), , User.UserRoles.Any(y = > y.Role.Name = = "" )? , , ?
: , UserRole , :
public class UserRoleEntity : Entity
{
public UserRole UserRole { get; set; }
public Guid EntityId { get; set; }
public EntityType EntityType { get; set; }
}
User Role , , .