The dbml file contains the following test model:
Model http://www.freeimagehosting.net/uploads/a86582498a.gif
In the test case, the table has 4 entries, 1 parent, 3 children. We are looking for siblings for a particular record, including a specific record.
using (var db = new TestDataContext())
{
var query =
from f in db.Foos
where f.Name == "Two"
select f.Foo1.Foos;
var foos = query.SelectMany(f => f);
Assert.AreEqual(3, foos.Count());
}
This returns the correct elements with the following SQL:
SELECT [t2].[FooId],
[t2].[ParentFooId],
[t2].[Name]
FROM [dbo].[Foos] AS [t0]
INNER JOIN [dbo].[Foos] AS [t1] ON [t1].[FooId] = [t0].[ParentFooId]
CROSS JOIN [dbo].[Foos] AS [t2]
WHERE ([t0].[Name] = @p0)
AND ([t2].[ParentFooId] = [t1].[FooId])
We wonder about CROSS JOIN, is this apparently the result of SelectMany?
Is there any other way we should approach in order not to have CROSS-JOIN?
source
share