我想使用包括一些選擇這樣的關鍵字:包括與擴展方法關鍵字不提供過濾
context.Categories.Include(c => c.Products)
我已經搜索互聯網上,發現下面的方法:
public static class ObjectQueryExtension
{
public static ObjectQuery<T> Include<T>(this ObjectQuery<T> mainQuery,Expression<Func<T, object>> subSelector)
{
return mainQuery.Include(((subSelector.Body as MemberExpression).Member as System.Reflection.PropertyInfo).Name);
}
}
當我有複製粘貼這個方法在我的項目,當我打字
context.category.include()//
那麼它只是顯示我用字符串作爲像參數:
context.category.include("");//like this
我想使用包括關鍵字像這樣:
context.Categories.Include(c => c.Products)
任何機構可以TEMM我什麼問題???
只需添加「使用EntityFramework;」你的班級 – ErikEJ 2014-10-10 07:36:40