【问题标题】:EntitySqlException was unhandled by user code?EntitySqlException 未被用户代码处理?
【发布时间】:2012-08-01 05:06:50
【问题描述】:

运行我的 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);
        }

【问题讨论】:

    标签: c#-4.0 entity-framework-4.1


    【解决方案1】:

    当您使用 ESQL 时,您必须使用实体别名来访问属性。默认别名为it,因此您必须使用"it.CategoryID"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多