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);
        }

2
  • Possible duplication of thread stackoverflow.com/questions/18351898/… Commented Sep 12, 2022 at 10:48
  • delete obj and bin folder and then rebuild the project. That solves my problem. Commented Sep 12, 2022 at 11:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.