过滤ASP.NET Linq到实体中的子元素

时间:2022-11-30 17:56:37

I have the following type of situation:

我有以下类型的情况:

TABLE Customers (
    CustomerID int,
    etc... )

TABLE Orders (
    OrderID int,
    CustomerID int,
    Active bit,
    etc... )

I am using this in an ASP.NET MVC web application using Linq-to-Entities. I want to select all Customers and populate the Customer.Orders navigational property, and should only be populated with orders where Active==true.

我在使用Linq-to-Entities的ASP.NET MVC Web应用程序中使用它。我想选择所有客户并填充Customer.Orders导航属性,并且只应使用Active == true的订单填充。

I've seen other questions that point to DataLoadOptions.AssociateWith, but it appears I can't use that in ASP.NET. I've also seen this article, but it appears I would need to be calling CreateSourceQuery() in my view as I enumerate through Customers. This is possible, I suppose, but seems to be breaking MVC paradigm.

我已经看到了其他指向DataLoadOptions.AssociateWith的问题,但似乎我无法在ASP.NET中使用它。我也看过这篇文章,但似乎我需要在我的视图中调用CreateSourceQuery(),因为我通过Customers枚举。我认为这是可能的,但似乎打破了MVC范式。

This seems to be a similar situation to "Filter child collection using a child collection of the child" except I need a solution for Linq-to-Entities instead of NHibernate. Thanks!

这似乎与“使用子集合的子集合过滤子集合”的情况类似,除了我需要Linq-to-Entities而不是NHibernate的解决方案。谢谢!

1 个解决方案

#1


You can find the answer in this tip.

您可以在此提示中找到答案。

#1


You can find the answer in this tip.

您可以在此提示中找到答案。