How to include a child object’s child object in Entity Framework 5

If you include the library System.Data.Entity you can use an overload of the Include() method which takes a lambda expression instead of a string. You can then Select() over children with Linq expressions rather than string paths. return DatabaseContext.Applications .Include(a => a.Children.Select(c => c.ChildRelationshipType));

EF LINQ include multiple and nested entities

Have you tried just adding another Include: Course course = db.Courses .Include(i => i.Modules.Select(s => s.Chapters)) .Include(i => i.Lab) .Single(x => x.Id == id); Your solution fails because Include doesn’t take a boolean operator Include(i => i.Modules.Select(s => s.Chapters) && i.Lab) ^^^ ^ ^ list bool operator other list Update To learn more, download LinqPad … Read more

What’s the difference(s) between .ToList(), .AsEnumerable(), AsQueryable()?

There is a lot to say about this. Let me focus on AsEnumerable and AsQueryable and mention ToList() along the way. What do these methods do? AsEnumerable and AsQueryable cast or convert to IEnumerable or IQueryable, respectively. I say cast or convert with a reason: When the source object already implements the target interface, the … Read more

Non-static method requires a target

I think this confusing exception occurs when you use a variable in a lambda which is a null-reference at run-time. In your case, I would check if your variable calculationViewModel is a null-reference. Something like: public ActionResult MNPurchase() { CalculationViewModel calculationViewModel = (CalculationViewModel)TempData[“calculationViewModel”]; if (calculationViewModel != null) { decimal OP = landTitleUnitOfWork.Sales.Find() .Where(x => x.Min … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)