简体   繁体   English

无法识别ASP.NET Web应用程序名称空间

[英]ASP.NET web application namespace not recognized

I have created an ASP.NET Web Application, Web Form. 我创建了一个ASP.NET Web应用程序Web窗体。

I have added EntityFramework 6.2 我添加了EntityFramework 6.2

I have mapped the DB using Code First From Existing Database 我已经从现有数据库中使用代码优先映射数据库

Everything went fine, I have all the classes with the context like below: 一切顺利,我有所有带有如下上下文的类:

namespace MyProject.DataModel
{
    using System;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;

    public partial class MyDBEntities : DbContext
    {
        public MyDBEntities ()
            : base("name=MyDBEntities ")
        {
        }

        public virtual DbSet<Adm0> Adm0 { get; set; }
        public virtual DbSet<Adm1> Adm1 { get; set; }
        public virtual DbSet<Adm2> Adm2 { get; set; }
        public virtual DbSet<Country> Countries { get; set; }
        ...

The connection string is: 连接字符串为:

  <connectionStrings>
    <add name="MyDBEntities" connectionString="data source=10.11.xx.xx;initial catalog=xxxxxx;persist security info=True;user id=xxxx;password=xxxxxx;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
  </connectionStrings>

No error in the whole project, but if I try to access the DbContext there is no way! 整个项目中没有错误,但是如果我尝试访问DbContext,那是没有办法的! The namespace DataModel doesn't exist anywhere, is completely ignored: 名称空间DataModel在任何地方都不存在,将被完全忽略:

Example: 例:

Typing MyProject. 键入MyProject。 Intellisense doesn't suggest DataModel Intellisense不建议使用DataModel

Typing MyProject.DataModel it gives error on DataModel saying that doesn't exist. 键入MyProject.DataModel,它会给出有关不存在的DataModel错误的信息。

Why?? 为什么??

Have you more than a project in your solution? 您的解决方案中不只是一个项目吗? If so, you should add a reference between the project where you want to use your DbContext and the project that contains it. 如果是这样,则应在要使用DbContext的项目和包含它的项目之间添加引用。

From the official documentation: 从官方文档中:

To add a reference, right click on the References or Dependencies node in Solution Explorer and choose Add Reference Source 要添加引用,请在解决方案资源管理器中右键单击“引用或依赖项”节点,然后选择“添加引用源”。

Also, make sure that the project that contains the DbContext is being compiled. 另外,请确保正在编译包含DbContext的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM