Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何取回所有“客户”对象以及在LINQtoSQL中仅“打开”的“订单”?_C#_Sql Server_Linq - Fatal编程技术网

C# 如何取回所有“客户”对象以及在LINQtoSQL中仅“打开”的“订单”?

C# 如何取回所有“客户”对象以及在LINQtoSQL中仅“打开”的“订单”?,c#,sql-server,linq,C#,Sql Server,Linq,我知道如何获得客户及其所有订单: //Get data context for the SQL Server connection DataContext connection = new DataContext(getConnection()); //Customer table to query against Table<Customer> customers = connection.GetTable<Customer>(); //This query giv

我知道如何获得客户及其所有订单:

//Get data context for the SQL Server connection
DataContext connection = new DataContext(getConnection());

//Customer table to query against
Table<Customer> customers = connection.GetTable<Customer>();

//This query gives all customers and ALL their orders
IQueryable<Customer> query = 
    from customer in customer
    where customer.id == custId select customer;

您可以在第一次查询后直接查询客户,因为它是一个IQueryable so

var onlyOpen = customer.where(x=> x.orders._status = "Open");

我可以使用DataLoadOptions完成此操作:

var onlyOpen = customer.where(x=> x.orders._status = "Open");
public virtual void addAssociationFilter<T>(Expression<Func<T, object>> filter, DataContext dataContext)
{
    //We'll use this to restrict our main object's entity list property
    DataLoadOptions restrictList = new DataLoadOptions();

    //We only want ops that are current or finished
    restrictList.AssociateWith<T>(filter);

    //Set on our context
    dataContext.LoadOptions = restrictList;
}

//Call like:
addAssociationFilterJCustomer>(
    cust => cust.orders.Where(o => o.status == "Open"),
    dataContext
);