0

Here I'm doing a first-time .net MVC Database First approach project.

I have connected my existing database to the project.

When I try to retrieve the data from it to the controller, I got error message "System.Data.Entity.Core.MetadataException: Unable to load the specified metadata resource."

Any reason why this happens ?

This is my connection string. It was automatically added when I'm connecting to the database.

<connectionStrings>
  <add name="Entitiesdb" connectionString="metadata=res://*/Models.zSql.csdl|res://*/Models.zSql.ssdl|res://*/Models.zSql.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-N4UN8GE;initial catalog=MondoErp-UAT;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

This is the dataModel.Context file

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

  protected override void OnModelCreating(DbModelBuilder modelBuilder) {
    throw new UnintentionalCodeFirstException();
  }
  public virtual DbSet < Nationality > Nationality {
    get;
    set;
  }
   
}

This is how my Controller

private zSql db = new zSql();

        public ActionResult Index()
        {
            IEnumerable<NationalityModel> nationalities = db.Nationality.Select(x=> new NationalityModel
            {
                IDNationality= x.IDNationality,
                Name = x.Name,
                Description = x.Description
            }).ToList();

            return View(nationalities);
        }

Dev Beginner
  • 589
  • 1
  • 11
  • Possible duplication of thread https://stackoverflow.com/questions/18351898/system-data-metadataexception-unable-to-load-the-specified-metadata-resource – asmak9 Sep 12 '22 at 10:48
  • delete **obj** and **bin** folder and then **rebuild** the project. That solves my problem. – Abdul Haseeb Sep 12 '22 at 11:04

0 Answers0