none
Filter a query within the select statement. ie. where clause in select.

    Question

  • I have this linq query:

    var sku = (from a in con.MagentoStockBalances
                               join b in con.MFGParts on a.SKU equals b.mfgPartKey
                               join c in con.DCInventory_Currents on b.mfgPartKey equals c.mfgPartKey
                               where a.SKU != 0 && c.dcKey ==6
                               select new
                               {
                                   Part_Number = b.mfgPartNumber,
                                   Stock = a.stockBalance,
                                   Recomended = a.RecomendedStock,
                                   Cato = c.totalOnHandQuantity
                               }).ToList();

    Now i need to remove the c.dcKey ==6 condition and have something like this:

                    var sku = (from a in con.MagentoStockBalances
                               join b in con.MFGParts on a.SKU equals b.mfgPartKey
                               join c in con.DCInventory_Currents on b.mfgPartKey equals c.mfgPartKey
                               where a.SKU != 0
                               select new
                               {
                                   Part_Number = b.mfgPartNumber,
                                   Stock = a.stockBalance,
                                   Recomended = a.RecomendedStock,
                                   Cato = c.totalOnHandQuantity where c.dcKey == 6,
                                   Kerry = c.totalOnHandQuantity where c.dcKey == 7
                               }).ToList();

    Any Ideas on how to do this would help a lot.


    Thursday, June 13, 2013 5:23 PM

Answers

  • I figured it out(with help from another forum). If any one is interested this is how it went.

                                   Cato = (c.dcKey == 6) ? c.availableQuantity : 0,
                                   Kerry = (c.dcKey == 7) ? c.availableQuantity: 0

    • Marked as answer by Aaron Lehaney Thursday, June 13, 2013 7:31 PM
    Thursday, June 13, 2013 7:31 PM

All replies

  • Hi Aaron;

    What is wrong with the second query? Are you getting an exception? Is it not returning the correct results?

    It looks like it should work.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, June 13, 2013 6:44 PM
  • The second query will not even compile. I was just showing it to explain what I wanted to do.
    Thursday, June 13, 2013 7:01 PM
  • I figured it out(with help from another forum). If any one is interested this is how it went.

                                   Cato = (c.dcKey == 6) ? c.availableQuantity : 0,
                                   Kerry = (c.dcKey == 7) ? c.availableQuantity: 0

    • Marked as answer by Aaron Lehaney Thursday, June 13, 2013 7:31 PM
    Thursday, June 13, 2013 7:31 PM