Hi @Malam Malam,
DbContext Class needs to be implemented using Entity Framework. If you do not want to use Entity Framework, you can use ADO.NET, for example:
public ActionResult Index()
{
List<Emplyee> employeeList = new List<Emplyee>();
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("SELECT * FROM Employees", con);
cmd.CommandType = CommandType.Text;
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
var employee = new Emplyee();
employee.EmployeeId = Convert.ToInt32(rdr["EmployeeId"]);
employee.Name = rdr["Name"].ToString();
employee.Gender = rdr["Gender"].ToString();
employee.Age = Convert.ToInt32(rdr["Age"]);
employee.Position = rdr["Position"].ToString();
employee.Office = rdr["Office"].ToString();
employee.HireDate = Convert.ToDateTime(rdr["HireDate"]);
employee.Salary = Convert.ToInt32(rdr["Salary"]);
employeeList.Add(employee);
}
}
return View(employeeList);
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.