EF4 LINQ Include(string) alternative to hard-coded string?
问题 Is there any alternative to this: Organizations.Include("Assets").Where(o => o.Id == id).Single() I would like to see something like: Organizations.Include(o => o.Assets).Where(o => o.Id == id).Single() to avoid the hard-coded string "Assets". 回答1: For Entity Framework 1.0, I created some extensions methods for doing this. public static class EntityFrameworkIncludeExtension { public static ObjectQuery<T> Include<T>(this ObjectQuery<T> src, Expression<Func<T, StructuralObject>> fetch) { return