开发者

RIA Service ObjectContext filter included records

开发者 https://www.devze.com 2023-02-15 07:59 出处:网络
Using RIA Domain services with entity framework 4, I am having trouble to get the entity with filtered related items.

Using RIA Domain services with entity framework 4, I am having trouble to get the entity with filtered related items.

For Example, Given: Order table and Product table (1 order has many products)

I have service returns Order with Products loaded, e.g.

    public IQueryable<Order> GetOrderById(int orderId)
    {
        return this.ObjectContext.Order
                                 .Include("Products")
                                 .Where(n=>开发者_Go百科n.OrderId == orderId);
    }

Question,

Is there a way to filter the Products record in the linq query in this case? Say, return the order of the specified Id and include the Products which prices are higher than 100.0; return Empty/Null Products if there isn't any. The point here is to return the Order even though there isn't any products meet the criteria.


Have you tried something like this:

var query = from o in ObjectContext.Order.Include("Products")
            join p in ObjectContext.Product on o.ProductId equals p.ProductId
            where o.OrderId == orderId and p.Price > 100
            select o;
0

精彩评论

暂无评论...
验证码 换一张
取 消