C# 对IQueryable的导航属性使用扩展方法

C# 对IQueryable的导航属性使用扩展方法,c#,linq-to-sql,linq-to-entities,entity-framework-5,extension-methods,C#,Linq To Sql,Linq To Entities,Entity Framework 5,Extension Methods,在LINQtoEntities中,是否可以在IQueryable中的实体的导航属性上使用扩展方法 例如,如果我有一个具有导航属性产品的制造商实体,我可以执行以下操作: // ManufacturersQuery is an IQueryable<Manufacturer> from m in ManufacturersQuery let p = m.Products.ReturnableProducts() where ... select ... // Extension met

在LINQtoEntities中,是否可以在IQueryable中的实体的导航属性上使用扩展方法

例如,如果我有一个具有导航属性产品的制造商实体,我可以执行以下操作:

// ManufacturersQuery is an IQueryable<Manufacturer>
from m in ManufacturersQuery
let p = m.Products.ReturnableProducts()
where ...
select ...

// Extension method - This throws the error "LINQ to Entities does not recognize the method ReturnableProducts and this method cannot be translated into a store expression."
public static IEnumerable<Product> ReturnableProducts(this IEnumerable<Product> products)
{
    return products.Where(p => p.IsReturnable);
}
我认为如果导航属性m.Products返回IQueryable而不是ICollection,这可能是可能的,但我不知道这是否可以更改


这能做到吗?谢谢

如果您希望它成为查询的一部分,则需要是IQueryable,否则您可以访问它,但只能在调用ToList之后