When I try to access my db context as so, i am able to access other tables through my results:
MyEntities myEnt = new MyEntities();
var comments = myEnt.Comments.Where(x=>x.UserName == UserName);
foreach(Comment comment in comments){
string FirstName = comment.UserProfile.FirstName;
}
My intellisense pulls up foreignkey mapping and allows me to access the joined table UserProfile
. Is this a bad practice to "chain" my results this way as opposed to doing a standard linq query with a join like so:
var query = from comments in myEnt.Comments
join up in myEnt.UserProfiles on comments.UserId equals up.UserId
select new {...}
UPDATE
Also what if I trail in even further such as:
comment.aspnet_Users.UserProfiles.UserRatings.ToList()
I tried something similar and it seemed like the query took much longer when I tried this approach over the 2nd. The intellisense lets you trail in quite a bit to related tables, does that play a factor on speed if i link through multiple tables like this?