加入ASP.net中的实体类查询

时间:2014-02-20 11:08:25

标签: linq

我有2个实体类(Code First Approach)

1]

 public class tblDepartment
    {
        public int id { get; set; }
        public string deptName { get; set; }
        public string address { get; set; }
        **public List<tblEmp> empId { get; set; }**
    }

2]

 public class tblEmp
    {
        public int id { get; set; }
        public string firstName { get; set; }
        public string lastName { get; set; }
        public double salary { get; set; }
    }

现在我想在tblEmp.id&amp;上执行连接操作。 tblDepartment.empId 我正在尝试这种方法:

var result = from d in _Context.tblDepartment
                     join e in _Context.tblEmp on d.empId equals e.id
                     select new
                     {
                         e.firstName,d.deptName

                     };

但它在“加入”关键字

下显示错误

1 个答案:

答案 0 :(得分:0)

试试这个:

var result = from d in _Context.tblDepartment
             from e in _Context.tblEmp 
             where d.empId equals e.id
             select new
             {
                 e.firstName,d.deptName
             };