xplat
xplat

Reputation: 8624

LINQ Query returns nothing

Why is this query returns 0 lines?

There is a record matching the arguments.

SomeDataContext db = new SomeDataContext(ConnString);

return db.Deafkaw.Where(p => 
      (p.SomeDate1 >= aDate && 
         p.SomeDate1 <= DateTime.Now) &&
      (p.Year == aYear && p.IsSomething == false)
  ).ToList();

Am i missing something?

On the Table Deafkaw

SomeDate1 = 20/4/2010 11:32:17 Year = 2010 IsSomething = False

...besides other columns im not interested in conditions.

I need SomeDate1 between the dates i give IsSomething = False and Year = 2010.

Upvotes: 1

Views: 191

Answers (4)

Mark Byers
Mark Byers

Reputation: 838106

You aren't assigning the result to anything so it is being discarded. Try this:

var results = db.Deafkaw.Where(p => 
         (p.ImerominiaKataxorisis >= aDate && 
          p.ImerominiaKataxorisis <= DateTime.Now) &&
         (p.Year == etos && p.IsYpodeigma == false)
     ).ToList();

Update: you changed the question so now I'm not sure that this is the correct answer. Can you post the code where you call this method?

Upvotes: 3

Raj Kaimal
Raj Kaimal

Reputation: 8304

Use SQL profiler. Look at the sql query that is generated. Run the sql query manually and see if you get back any records.

Upvotes: 0

Tomas Petricek
Tomas Petricek

Reputation: 243041

It is difficult to answer your question without any additional information. Checking the following points may help you to find the problem:

  • If you remove Where clause and write Deafkaw.ToList(), what do you get?
  • What is the value of aDate and etos?
  • Can you double check the condition? Do you require that all subconditions hold at the same time? Are there any such data if you print entire DeaFkaw data structure?
  • Can you try removing some sub-conditions to see if that gives you some results?

Upvotes: 2

Christopher Edwards
Christopher Edwards

Reputation: 6659

Try

Deafkaw.Where(p => (p.ImerominiaKataxorisis >= aDate && p.ImerominiaKataxorisis <= DateTime.Now &&
            p.Year == etos && p.IsYpodeigma == false)).ToList();

Upvotes: 0

Related Questions