由于其保护级别,“BusinessLayer.EmployeeBusinessLayer”无法访问

时间:2015-05-31 09:13:48

标签: asp.net-mvc

在一个名为(BusinessLayer)的classLiberary中

我创建了一个类Employee.cs --->

public class Employee
    {
        public int EmployeeId { get; set; }
        public string EmployeeName { get; set; }
        public string EmployeeCity { get; set; }
        public string EmployeeGender { get; set; }
        public int DepartmentId { get; set; }
    }

然后添加了另一个类EmployeeBusinessLayer.cs

class EmployeeBusinessLayer
    {
        public IEnumerable<Employee> Employees
        {
            get
            {
                string ConnectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                 List<Employee> employees = new List<Employee>();
                using (SqlConnection con = new SqlConnection(ConnectionString))
                {
                    SqlCommand cmd = new SqlCommand("sqlGetAllEmployees", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    con.Open();
                    SqlDataReader rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        Employee employee = new Employee();
                        employee.DepartmentId = Convert.ToInt16(rdr["DepartmentId"]);
                        employee.EmployeeId = Convert.ToInt16(rdr["EmployeeId"]);
                        employee.EmployeeName = rdr["EmployeeName"].ToString();
                        employee.EmployeeCity = rdr["EmployeeCity"].ToString();
                        employee.EmployeeGender = rdr["EmployeeGender"].ToString();
                        employees.Add(employee);

                    }
                }
                return Employees;
            }


        }
    } 

然后当我在添加引用后在我的项目中使用它时,它显示“BusinessLayer.EmployeeBusinessLayer”由于其保护级别而无法访问“

 public class EmployeesController : Controller
        {

            public ActionResult Index()
            {
   EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
              List<Employee> employees =  employeeBusinessLayer.Employees;
                return View(employees);
            }

        }

1 个答案:

答案 0 :(得分:0)

您需要让Controller类可以访问EmployeeBusinessLayer。

您可以将其公之于众:

public class EmployeeBusinessLayer {  ...