In my SQL Server database, there are 3 tables.
features two columns.
which serve as the other two tables' foreign keys.
Due to this, Entity Framework just needs to create two classes and add virtual properties when creating the model for it.
into each position and type of permissions.
I must now choose columns from
Consequently, I wrote the following code:
var rolePermission = PREntitiy.Roles.Where(r => r.qRole == TxtRole.Text) .Select(p => p.Permissions);
By doing this, I have access to
table, but I must obtain a few columns from the role table and a few columns from the
similar to how we would write a SQL join statement in a single query.
Alternatively, I require a Linq query to obtain some columns from the Role table and some from
However, I must accomplish it in a single Linq query, much like a SQL join statement.
@BlackICE His advice was quite helpful to me. Although not the same, I experienced a similar issue. I have three tables: UserRoles, Roles (RoleId, RoleName), and Users (Username, Password) (Username, RoleId). Keys from the first two were combined to create the last. Given the username, I had to complete the following in order to receive the role. I'm not sure if this is right or wrong, but it seemed to work for me:).
IQueryable<User> IQUsers = _dbContext.Users.Include(u => u.Roles).Where(u => u.Username == username); User _user = IQUsers.FirstOrDefault<User>(); Role _role = _user.Roles.FirstOrDefault<Role>(); roleName = _role.RoleName;