Search code examples
linqlinq-to-entitiesoracle10g

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.


Solution

  • I will be following John Skeet answer as posted by Vossad01.

    Proper Linq where clauses