InnerJoin操作:
private void InnerJoinQuery()
{ ///构建数据源
List<UserInfo> users = new List<UserInfo>();
List<RoleInfo> roles = new List<RoleInfo>();
for (int i = 1; i < 10; i++)
{
users.Add(new UserInfo(i, "User0" + i.ToString(),"User0" + i.ToString() + "@web.com",i * 2));
roles.Add(new RoleInfo(i,"RoleName0" + i.ToString())); u.RoleID
}
///查询ID值小于9,且角色包含在roles中的用户
var value = from u in users
where u.ID < 9
join r in roles on u.RoleID equals r.ID //找出u.RoleID与r.ID相同的u和r
select new
{
u.Username,
r.RoleName
};