【问题标题】:EntityFramework DataContext is not recognizedEntityFramework DataContext 无法识别
【发布时间】:2017-10-28 10:30:37
【问题描述】:

我正在将以前工作的应用程序从 WebForms 网站移动到 Web 应用程序。当我尝试实现实体框架引用时,系统无法识别实体模型。我有一个保存为“CustomerSurveyDBEntities.edmx”的数据模型,NuGet 显示我安装了 EntityFramework v6.1.3。它显示 System.Data.Entity 当前未在此范围内使用。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//...this is greyed out
using System.Data.Entity;
//...
//This is where my entity model is no longer recognized
using (CustomerSurveyDBEntities myEntities = new CustomerSurveyDBEntities())

【问题讨论】:

    标签: asp.net entity-framework webforms


    【解决方案1】:

    这似乎是一个范围界定问题。虽然在 App_Code 文件夹中使用 .edmx 模型的现有文件结构与旧代码一起使用,但此问题已通过删除旧模型并将新的代码优先模型添加到项目根目录中得到解决。可以在这里找到更好的解释:

    https://channel9.msdn.com/Blogs/EF/Code-First-to-Existing-Database-EF6-1-Onwards-

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-28
      • 1970-01-01
      • 2018-10-11
      • 1970-01-01
      相关资源
      最近更新 更多