Sorry about this - I'm new to entity framework and I'm not having much luck finding an answer anywhere else.
I have 2 tables, Users and Roles, with a many to one relationship.
Using SQL to get the users role name I'd do something like this:
SELECT r.Name
FROM Role r
INNER JOIN User u ON u.RoleID = r.ID
WHERE u.UserName = 'someusername'
So in EF I think I should be able to do something like this:
string role = context.Users.Single(u => u.UserName == username).Role.Name;
This works fine but when the code runs it executes 2 queries on the SQL server - one to get the user from the user table and another to get the role from the roles table. This obviosuly seems very heavy compared to the SQL code above so I was wondering how I could make it more efficient and execute in a single query.
Thanks