我想加入我的兩個表linq基於一個id,迄今不正常。如何使用linq連接兩個表?
這裏是我的模型的樣子:
public class WorkRole
{
public int WorkRoleId { get; set; }
public string RoleName { get; set; }
public string RoleDescription { get; set; }
public int CompanyId { get; set; }
public virtual Company Company { get; set; }
public virtual ICollection<WorkRolesUsersDetails> WorkRolesUsersDetails { get; set; }
}
public class WorkRolesUsersDetails
{
public int WRUDId { get; set; }
public int? WorkRoleId { get; set; }
public string UserDetailsId { get; set; }
public virtual WorkRole WorkRole { get; set; }
public virtual UserDetails UserDetails { get; set; }
public DateTime FocusStart { get; set; }
public DateTime FocusEnd { get; set; }
public bool isActive { get; set; }
}
我想在一個視圖中WorkRoleId,角色名,RoleDescription和CompanyId從第一個表和第二個表UserDetailsId,FocusStart,FocusEnd和isActive得到。
我有我的想法得到了最遠的是:
var query = db.WorkRoles.Join(db.WorkRolesUsersDetails,x => x.WorkRoleId,y => y.WorkRoleId,(x, y) => new { wr = x, wrud = y });
但可悲的是,它沒有工作。我只是不知道足夠多的linq,並且無法從這裏獲得其他問題/答案。請幫忙。
您did'nt意味着什麼工作,任何異常或預期的結果did'nt來的? –