Entity Framework .Include() with compile time checking?
- by Mikey Cee
Consider the following code, which is calling against an EF generated data context:
var context = new DataContext();
var employees = context.Employees.Include("Department");
If I change the name of the entity Department then this code is going to start throwing a runtime error. So I'll have to do some kind of find and replace throughout my code to replace each occurrence of "Department".
Is there any way to call the .Include() method in a safe manner, so I get compile time checking for all the entity names being referenced?