0
我知道如何讓客戶和他們的所有訂單:如何獲取Linq to SQL中所有「客戶」對象和僅「打開」的「訂單」?
//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;
但如何獲取客戶只需與它的命令爲status = "Open"
?
類:
[Table(Name = "Customers")]
public class Customer
{
...elided...
private EntitySet<Order> _orders;
[Association(Storage = "_orders", OtherKey = "orderId")]
public EntitySet<Order> orders
{
get
{
return this._orders;
}
set
{
this._orders.Assign(value);
}
}
}
[Table(Name = "Orders")]
public class Order
{
...elided...
private string _status;
[Column(Storage="_status")]
public string _status
{
get { return this._status; }
set { this._status = value; }
}
}