I am following this tutorial: http://www.w3schools.com/aspnet/mvc_models.asp, to get data from SQL CE
using Entity Framework. There doesn't seem to be much code. The tutorial is for MVC3 but my project is MVC4, but I think major steps should be same.
I created a SQL CE
database, and a table with needed columns.
Added data to the table.
On the C# side I have
namespace MvcDemoApp.Models
{
public class Employee
{
public int EmployeeID { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public string City { get; set; }
}
public class EmployeeContext : DbContext
{
public DbSet<Employee> employees { get; set; }
}
}
And code in respective controller
public ActionResult Index()
{
var c = db.employees.ToList();
return View(c);
}
That sample is for movies database, I changed all relevant info to employees. I added the connection string as in that tutorial too. But when I navigate to the Index page of above controller, there is exception, please see exception details at bottom.
It seems I gave correct meaning to table columns too (e.g. similar to Employee class properties)
PS. This is how the DB looks after I stop running the app
So what is the correct way to load data from SQL Compact using entiry framework in ASP MVC 4 application?
This is list of data providers on my machine, I printed it using some code I found:
this is my connection string
<connectionStrings> <add name="EmployeeContext" connectionString="Data Source=c:\users\g\documents\visual studio 2012\Projects\TestMVCApp\TestMVCApp\App_Data\EmployeeDB.sdf" providerName="System.Data.SqlServerCe.4.0" /> </connectionStrings>
UPDATE: This is the exception I get now:
Exception Details: System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.
Source Error:
Line 17: Line 18: EmployeeContext e = new EmployeeContext(); Line 19: var list =e.Employeeslist.ToList();//exception here