質問

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