是否可以從LinqToSql(或EF)查詢返回多個實體(查詢位於方法內部),以便結果仍可組合?從LinqToSQL(或EF)返回多個實體
事情是這樣的:
public IQueryable<KeyValuePair<Customer, Product>> GetCustomerEntities()
{
return
(
from customer in this.Context.Customers
join
product in this.Context.Products on customer.ID equals product.CustomerID
select new KeyValuePair<Customer, Product>(customer, product)
);
}
然後我想用這個方法的結果,以進一步構成,如查詢:
this.GetCustomerEntities().Where(e => e.Key.Name == "my customer")
上述編譯方法,但它不能被執行通過LinqToSql,因爲它不能將KeyValuePair轉換爲SQL,這是預期的行爲。
是否有可能以某種方式實現這一點?
謝謝,它的工作原理!我可以在不執行SQL的情況下編寫查詢。 – SzilardD