DDL for Database Tables:
Users:
id - int - identity
name - varchar - unique
PCs:
id - int - idnetity
name - varchar - unique
userid - FK to Users
Apps:
id - int - identity
name - varchar
pcid - FK to PCs
I created a DataContext using the Linq To SQL designer in Visual Studio 2008.
I want to perform this query:
select
users.name,
pcs.name,
apps.name
from
users u
join pcs p on p.userid = u.id
join apps a on a.pcid = p.id
I was told in another thread where I posted an answer that the following was incorrect and that it created a cross-join.
var query = from u in db.Users // gets all users
from p in u.PCs // gets all pcs for user
from a in p.Apps // gets all apps for pc
select new
{
username = u.Name,
pcname = p.Name,
appname = a.Name
};
When I execute this query I get the correct results. A cross-join with two records in each table should return 8 records but my query correctly returns the two records.
Am I lucky, or is the person telling me that I'm wrong confused?