Andrio
Andrio

Reputation: 2078

Using LINQ, why can't Include() have a lambda expression when It's worked in the past?

I have this code to return all employees in my db. Each employee contains a collection of dependents.

var employees = _dbContext.Employees.Include(e => e.Dependents).ToList();

Problem is, it's telling me Include() can only take in a string. I know I've used it with a lambda expression in the past. Why won't it let me now?

If I do use Include("Dependents") it does work correctly, but I'd like to avoid relying on a string.

Upvotes: 0

Views: 71

Answers (1)

Andrio
Andrio

Reputation: 2078

Per the comments, I tried using System.Data.Entity and it fixed my problem. Thanks!

Upvotes: 3

Related Questions