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 an 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="data source=DESKTOP-N4UN8GE;initial catalog=MondoErp-UAT;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
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);
}