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
  • 101,031
  • 48
  • 228
  • 272
Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
  • 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
  • 20,441
  • 9
  • 58
  • 74
Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272