1

I was trying to figure out how to replace the nested from clause to a method syntax. I was trying with .Select or .SelectMany, but I didn't manage to get the same result.

  var query = (from DirectToStoreStore s in dtsOrder.Stores
                        from DirectToStoreProduct p in s.Products
                        where p.DirectToStoreOrderLineID == directToOrderLineID
                        select p);
Blorgbeard
  • 97,316
  • 47
  • 222
  • 267
Thiago Custodio
  • 15,655
  • 6
  • 41
  • 81
  • http://stackoverflow.com/questions/1524813/convert-this-linq-expression-into-lambda – Slai Aug 31 '16 at 04:26

1 Answers1

3

There's plenty of ways you could write it.

var query = dtsOrder.Stores.Cast<DirectToStoreStore>()
    .SelectMany(s => s.Products.Cast<DirectToStoreProduct>()
        .Where(p => p.DirectToStoreOrderLineID == directToOrderLineID)
    );

Though the casts may not be necessary, but they're only there since you explicitly declared them in your query. It'll probably be safe to remove them.

Hamid Pourjam
  • 19,792
  • 9
  • 57
  • 71
Jeff Mercado
  • 121,762
  • 30
  • 236
  • 257