我们在dbml文件中有以下测试模型:
这个SQL语句可以正确返回相应的数据项:
模型 http://www.freeimagehosting.net/uploads/a86582498a.gif
对于测试用例,表中有4条记录,1个父级和3个子级。我们正在寻找特定记录的兄弟姐妹,包括特定记录本身。using (var db = new TestDataContext())
{
var query =
from f in db.Foos
where f.Name == "Two"
select f.Foo1.Foos; // get the record's parent's children
var foos = query.SelectMany(f => f); // project the EntitySet
Assert.AreEqual(3, foos.Count()); // passes
}
这个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])
我们想了解CROSS JOIN,这显然是SelectMany的结果吗?
是否还有其他方法可以避免使用CROSS JOIN?