none
Difference between queries RRS feed

  • Question

  • Just reading one of the EF books, and I came to following:

    var query = context.Nationalities
                      .Where(n => n.Created.Date >= range.Begin.Date &&
                                          n.Created.Date <= range.End.Date);

    var query = context.Nationalities
                                 .Where(n => n.Created.Date >= range.Begin.Date)
                                 .Where(n => n.Created.Date <= range.End.Date);

     

    Is there any functional difference between these two queries? Results are same at least from test db. "range" here seems to be struct with begin and end date.

    Thursday, December 22, 2011 10:39 AM

Answers

  • Hi MasaSam;

    They will produce the same SQL query and return the same results. Multiple Where clauses are anded, &&, in the query.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by MasaSam Friday, December 23, 2011 6:58 AM
    Thursday, December 22, 2011 3:41 PM

All replies

  • Hi MasaSam;

    They will produce the same SQL query and return the same results. Multiple Where clauses are anded, &&, in the query.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by MasaSam Friday, December 23, 2011 6:58 AM
    Thursday, December 22, 2011 3:41 PM
  • I was pretty sure that is the way it is done. Just didn't know, was not explained in book, why this was pointed out.
    Friday, December 23, 2011 6:58 AM
  •  

    Not a problem, glad I was able to confirm the operation for you.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, December 23, 2011 3:16 PM