none
Linq to Entities: I would need an or in the where statement RRS feed

  • Question

  • Hi all,

    Simpified, I would need the following:

    var query = context.Orders

    .Where(o=>o.Status == "GEN" || o=>o.Status == "ANG").ToList();

    ------------

    var query = context.Orders

        .Where(o=>o.Date < myDate || o.Date > myDate2).ToList();

    I hope, you can understand what I need, and I hope someone can explain me how to do it.

    Thanks in advance

    Siegfried

    Monday, August 13, 2012 10:31 AM

Answers

  • Hi Siegfried;

    The first query should be this.

    var query = context.Orders
                       .Where( o => o.Status == "GEN" || o.Status == "ANG").ToList();
                       
    The second query looks like it should return results. Please post any exceptions that are thrown.

      

    Fernando (MCSD)

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

    Monday, August 13, 2012 1:33 PM

All replies

  • Hi Siegfried;

    The first query should be this.

    var query = context.Orders
                       .Where( o => o.Status == "GEN" || o.Status == "ANG").ToList();
                       
    The second query looks like it should return results. Please post any exceptions that are thrown.

      

    Fernando (MCSD)

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

    Monday, August 13, 2012 1:33 PM
  • Hi,

    As pointed by Siegfried it's best to always describe what happens. Have you checked the db to see if you do have matching rows for the query you are issuing ?


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Wednesday, August 15, 2012 12:18 PM
  • Hi Fernando,

    thank you very much, that works very well.

    Siegfried

    Thursday, August 16, 2012 8:24 AM
  • Hi Patrice,

    I am working on my first project and it was a syntax error. Thanks for your suggestion.

    Siegfried

    Thursday, August 16, 2012 8:25 AM
  •   

    Not a problem, glad I was able to help.

      


    Fernando (MCSD)

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

    Thursday, August 16, 2012 2:34 PM