Though I tried searching many post I din't get the solution. Issue in Entity Framework
Should the name of my connection string should be same as the table name provided in the DB?
Because when I gave the connection string name as the table name, I've not found any errors, but when I gave the DBContext as my connection string name,I got this exception.
An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code
Additional information: The connection string 'ProductContext' in the application's configuration file does not contain the required providerName attribute."
Here is my piece of code Model:
public class Product
{
public int id { get; set; }
public string Name { get; set; }
public int Quantity { get; set; }
public DateTime EntryDate { get; set; }
}
ProductContext
public class ProductContext: System.Data.Entity.DbContext
{
public DbSet<Product> Products { get; set; }
public ProductContext() : base("ProductContext") { }
}
Controller:
public class ProductController : Controller
{
ProductContext db = new ProductContext();
// GET: Product
public ActionResult Index()
{
var product = db.Products.ToList();
return View(product);
}
web.config:
<connectionStrings>
<add name="ProductContext" connectionString="Data Source=SHUTTHEFCUKUP;Initial Catalog=EntityFrameWork;Integrated Security=True;providerName=System.Data.EntityClient" />
</connectionStrings>
DB table:
select * from Product
columns:
id,
name,
quantity,
date_entry
Could anyone help me out as I'm new entity framework.I'm missing something.