Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using Linq with multiple where conditions

I have a class representing a table on database that is defined:

public class MyClass{
    public int MyClassId{get;set;}
    public string Name{get;set;} 
    public string LastNamw{get;set;}
    public DateTime From{get;set;}
    public DateTime To{get;set;}
}

On which I want to run some search query against oracle database.

Now the question is :

var list = context.MyClass
    .Where(x => x.From>= FromMyDate)
    .Where(x => x.To <= ToMyDate);


var list = context.MyClass
    .Where(x => x.From>= FromMyDate && x.To <= ToMyDate);

Is it better to use multiple rows with where condition or one? And why... please

As far as I understand, I use multiple where clauses when I want to search on result of the first condition.

like image 394
cpoDesign Avatar asked Jul 03 '12 15:07

cpoDesign


1 Answers

It shouldn't matter

You are just creating an Expression tree that is passed to the Oracle Provider and it is the provider's job to create the resultant SQL query. Even though the Expression tree would be slightly different between the two, it should still result in the same sql. I like to use a sql profiler to make sure my linq queries are producing efficient sql.

like image 178
Aducci Avatar answered Oct 21 '22 10:10

Aducci