简体   繁体   中英

Not sure how to filter this data

Let's say I have Order class as follows.

 class Order
    {
        public Guid ID { get; set; }
        public int ProductID { get; set; }
        public int CategoryID { get; set; }
    }

In order, I get a list of orders from database and populate in local list that is declared as follows.

List<Order> Orders = new List<Order>();

I also have a cached list of orders that only contains Order.ID field.

List<Guid> CachedOrderIDs;

Now I want to modify following query to include Orders that are presnted in CachedOrderIDs.

var o = Orders.Where(m => m.ProductID > 200 && m.CategoryID > 500).ToList();

How can I do this?

Use Contains method:

var o = Orders.Where(m => m.ProductID > 200 && 
                          m.CategoryID > 500 &&
                          CachedOrderIDs.Contains(m.ID)).ToList();

You could try this one:

var o = Orders.Where(m => m.ProductID > 200 && 
                          m.CategoryID > 500 &&
                          CachedOrderIDs.Contains(m.Guid)
             ).ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM