문제

For example:

 var emp = db.Employees
           .Include("CostCenter")
           .Single(e => e.Id == 123);

I do not like the idea of using magic strings to include navigation properties in my query, is there a more neat way of doing this? I am asking this because recently I changed a navigation property's name and I had to change this manually, it is just doesn't look nice.

도움이 되었습니까?

해결책

Yes, you can try to use lambda expressions. First of all include appropriate extensions in your project:

System.Data.Entity.DbExtensions 

Then add appropriate namespace:

using System.Data.Entity; 

Now you can start using this:

var emp = db.Employees
           .Include(x => x.CostCenter)
           .Single(e => e.Id == 123);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top