简体   繁体   中英

ASP.NET web application namespace not recognized

I have created an ASP.NET Web Application, Web Form.

I have added 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! The namespace DataModel doesn't exist anywhere, is completely ignored:

Example:

Typing MyProject. Intellisense doesn't suggest DataModel

Typing MyProject.DataModel it gives error on DataModel saying that doesn't exist.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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