0

I need my context to include the sonns by a condition, I need the rows that not deleted (logical delete).

I understood that I cannot add a condition to the include; so I want to filter the context, but it's not working.

var aa = ctx.aa
         .Include(t => t.vari)
         .ToList()
         .FirstOrDefault();

ctx.vari.Where(bi => bi.ID == 10 && bi.Deleted == 1).ToList();

Thanks!

s.s.
  • 3
  • 1
  • 3

2 Answers2

2

As codelahiru && hbulens pointed out, you missed the bi for ID.

Disclaimer: I'm the owner of the project Entity Framework Plus

The Query IncludeOptimized feature allows to filter with include and optimize the query performance at the same time (Support EF5, EF6)

var aa = ctx.aa
            .IncludeOptimized(t => t.vari.Where(bi => bi.ID == 10 && bi.Deleted == 1))
            .FirstOrDefault();

Documentation: EF+ Query IncludeOptimized

Jonathan Magnan
  • 10,874
  • 2
  • 38
  • 60
  • Looks beuatiful !! but I can't have EF Plus :( – s.s. Jun 28 '16 at 12:15
  • Is there a reason why you cannot use a third party library? The code is free & open source so if you want you can either grab the source from GitHub or contact me and I will send you a zip file with only the EF+ Query IncludeOptimized source code. – Jonathan Magnan Jun 28 '16 at 14:20
  • thanks' you are so kind. i will ask my boss – s.s. Jun 28 '16 at 17:27
0

This isn't going to be the most performant query. It would be better to drop the ToList()

 var aa = ctx.aa.Include(t => t.vari).ToList().FirstOrDefault(); 

 // You missed the variable before ID
 ctx.vari.Where(bi => bi.ID == 10 && bi.Deleted == 1).ToList();
hbulens
  • 1,872
  • 3
  • 24
  • 45
  • exactly what i did... – s.s. Jun 26 '16 at 11:09
  • Please edit with more information. Code-only and "try this" answers are discouraged, because they contain no searchable content, and don't explain why someone should "try this". We make an effort here to be a resource for knowledge. – abarisone Jun 27 '16 at 06:08
  • @abarisone Normally I'd agree with you but the scope of the issue is so small there is little need for explanation (it was merely a typo imo). – hbulens Jun 27 '16 at 06:55
  • oh! I did it, I needed to filter the contex without the .include sentence. I think that the sosns were included, i just needed to 'touch' them.... Thanks! – s.s. Jun 28 '16 at 12:10