开发者

LINQ Query returns nothing

开发者 https://www.devze.com 2022-12-27 16:35 出处:网络
Why is this query returns 0 lines? There is a record matching the arguments. SomeDataC开发者_运维百科ontext db = new SomeDataContext(ConnString);

Why is this query returns 0 lines?

There is a record matching the arguments.

SomeDataC开发者_运维百科ontext 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.


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?


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?


Try

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号