I have a solution in which there are two projects, one the main project and the other classLibery project for Entity Framework(Since I'm not able to create an ADO.Net Data Entity Model in ASP.Net core project) I added the reference of the ClassLibery project in the main project and created an object of it and I am able to access all the properties of the Entity model. But when I run the code I get an Exception
"InvalidOperationException: No connection string named 'DefaultConnection' could be found in the application config file. System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel()"
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\SchoolMate.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient" />
</connectionStrings>
I have the same connection string in both the projects. I tried the solutions given in this link and many other links but none could help.
My HomeController, i get the exception inside the Index method at
var i = Model1Entities.Products.Where(x => x.ProductId==1);
this is my complete home controller
public class HomeController : Controller
{
Entities Model1Entities;
public HomeController()
{
Model1Entities = new Entities();
}
public IActionResult Index()
{
var i = Model1Entities.Products.Where(x => x.ProductId==1);
return View();
}
}