开发者

Property in class is IEnumerable<TDto> get TDto.A == a

开发者 https://www.devze.com 2022-12-23 23:56 出处:网络
So I have a class is something like this public class Order { //some other stuff ... //setting the internal _orderItems collection ...

So I have a class is something like this

public class Order
{
    //some other stuff ... 
    //setting the internal _orderItems collection ...
    IEnumerable<OrderItems> OrderItems { get { return _orderItems; }
}

public class OrderItem
{
    //other stuff
    public string ProductName {get; set;}
}

If I have a collection of orders of some sort and have access via linq to the order, something like

 myOrderRespository.Where(x=>x.OrderItems)

Then I only have access to getEnumerator there, waht I would like it to be able to do something like

 myOrderRespository.Where(x=>x.OrderItems.ProductName == "Blah")

Is this possible? this is a made up scenario an开发者_运维问答d its pseudo code I m trying to simplify the problem so its easy to explain ( so please forgive me if there are a few errors) Cheers


You probably are looking for something like:

var results = myOrderRepository.Where(x => x.OrderItems.Any(item => item.ProductName == "Blah"));

This will return all Order instances with at least one OrderItem that has the ProductName of "Blah".

0

精彩评论

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