1.Your
ViewModelDemoVM
class have to contain
only the needed properties
from both tables and nothing more. So it should be like:
public class ViewModelDemoVM
{
public int DeptID { get; set; }
public string DeptName { get; set; }
public string EmpName{ get;set;}
}
2.You should do similar like in your first LINQ, but in this case to use the properties from your new class like below:
var getbothrecord = (from item in dbcontext.depts as a
join emp in dbcontext.Employee as b
on item.dept_id equals emp.emp_id
select new ViewModelDemoVM
{
DeptID = a.id;
DeptName = a.dept_name;
EmpName = b.emp_name;
}).ToList();