, - .. ?
.
int id = parent.ParentID;
var qry = from child in db.Children
where child.ParentID = id && child.Date > whatever
select child;
, SelectMany
:
using System;
using System.Linq;
using ConsoleApplication5;
class Program
{
static void Main(string[] args)
{
string id;
using (var ctx = new DataClasses1DataContext())
{
id = ctx.Customers.Select(x => x.CustomerID).First();
}
DateTime cutoff = DateTime.Today.AddMonths(-2);
using (var ctx = new DataClasses1DataContext())
{
ctx.Log = Console.Out;
var qry = from o in ctx.Orders
where o.CustomerID == id
&& o.OrderDate > cutoff
select o;
foreach (var order in qry)
{
Console.WriteLine(order.OrderID);
}
}
using (var ctx = new DataClasses1DataContext())
{
ctx.Log = Console.Out;
var qry = from c in ctx.Customers
where c.CustomerID == id
from o in c.Orders
where o.OrderDate > cutoff
select o;
foreach (var order in qry)
{
Console.WriteLine(order.OrderID);
}
}
}
}
TSQL ( - !):
SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [
t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[Sh
ipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPosta
lCode], [t0].[ShipCountry]
FROM [dbo].[Orders] AS [t0]
WHERE ([t0].[CustomerID] = @p0) AND ([t0].[OrderDate] > @p1)
SELECT [t1].[OrderID], [t1].[CustomerID], [t1].[EmployeeID], [t1].[OrderDate], [
t1].[RequiredDate], [t1].[ShippedDate], [t1].[ShipVia], [t1].[Freight], [t1].[Sh
ipName], [t1].[ShipAddress], [t1].[ShipCity], [t1].[ShipRegion], [t1].[ShipPosta
lCode], [t1].[ShipCountry]
FROM [dbo].[Customers] AS [t0], [dbo].[Orders] AS [t1]
WHERE ([t1].[OrderDate] > @p0) AND ([t0].[CustomerID] = @p1) AND ([t1].[Customer
ID] = [t0].[CustomerID])
, .