1

Schema

This is my entity class structure, also this is an entity framework 6, code first.

B_C table is the intermediate of B and C for their many to many relation, C_F respectively.

Starting from A i want to select all tables where a Date is in between F's EffectiveFrom and EffectiveTo. I have managed to include all tables but i need some help on the where clause. Also, the date scenario is a lot more complex than i explained, could it be done with Expression>?

This is my progress for now, but i feel i very far

            var portfolios = Repo.Filter<A>(f => Some_Array_of_Ids.Contains(f.Id))
                .Include("B.B_C.C.C_F.F")
                .Where(w => w.B_Id != null && 
                    w.B.B_C.Any(a => a.C.C_F.AsQueryable().Any(dateFilterExpr)));

Update: It looks like the w.B.B_C.Any() populates all the B_C table if the expression is true even once.

  • You should definitely look into using the [query keywords](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/query-keywords) available with `Linq`. – タコス Jul 31 '18 at 07:46
  • try making it like here: https://stackoverflow.com/a/40319559/8507673 – sTrenat Jul 31 '18 at 07:47
  • @sTrenat I did, but that is just an other way to express my includes. I have included all entities on my result, all i need now is to "filter" using effectiveFrom and EffectiveTo. My problem is the .Where() clause – Dimitris Laliotis Jul 31 '18 at 08:35
  • did you tried something like `Where(t => t.DATE > startDate && t.DATE < endDate);`? – sTrenat Jul 31 '18 at 08:50
  • In where clause "t" gives me the properties of A. I need a where clause in the properties of F – Dimitris Laliotis Jul 31 '18 at 09:02

0 Answers0