0

运行我的 c# 代码时出现上述错误:

'CategoryID' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near simple identifier, line 6, column 1.

C#

 public ActionResult Index()
        {
            foreach (Category category in GetCategories("", "CategoryID", "", 1, 10, 1))
            {
                //do something
            }

            return View();
        }


        public IQueryable<Category> GetCategories(string filterExpression, string sortExpression, string sortDirection, int pageIndex, int pageSize, int pagesCount)
        {
            NorthwindEntities db = new NorthwindEntities();
            if (!String.IsNullOrWhiteSpace(filterExpression))
                return db.Categories.OrderBy(sortExpression + " " + sortDirection).Skip(pageIndex * pageSize).Take(pageSize);
            else
                return db.Categories.OrderBy(sortExpression + " " + sortDirection).Skip(pageIndex * pageSize).Take(pagesCount * pageSize);
        }
4

1 回答 1

0

当您使用 ESQL 时,您必须使用实体别名来访问属性。默认别名是it所以你必须使用"it.CategoryID".

于 2012-08-01T08:26:22.843 回答