Vote count:
0
I am fairly new to Entity Framework and MVC. I can use the Entity Data Model Wizard (EDMW) on an existing SQL server database and automatically create the necessary classes (context, models,etc). Then pass the model (db.Employees.tolist()) to a view from the controller. Everything works fine and I can see the list of all the employees on the browser from the company.employees table.
However, I want to write the code myself without the help of EDMW or other tools to better understand the entity/MVC/database interactions. So I wrote the following code but can't seem to get the table displayed on the browser. I know I am missing something.
SQL SERVER: Schema.tablename (Acme.Employees)
public class AcmeContext : DbContext
{
public virtual DbSet<Employee> Employees { get; set; }
}
public class Employee
{
public int customerid {get; set;}
public string name {get;set;}
public string state {get;set;}
}
public ActionResult list()
{
var db = new AcmeContext();
return view(db.Employees.tolist());
}
<connectionStrings>
<add
name="AcmeContext"
connectionString="data source=localhost;initial catalog=Acme;integrated security=True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
What else is needed? Thanks
asked 39 secs ago
Code first with existing DB
Aucun commentaire:
Enregistrer un commentaire