方法一:数据控件绑定
protected void LinqServerModeDataSource1_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e)
{
ASPxGridView1.KeyFieldName = "RoleID";
e.KeyExpression = "RoleID";
e.QueryableSource = from r1 in eDataContext.Role
join r2 in eDataContext.Role on r1.ParentRoleID equals r2.RoleID
where r1.IsDeleted == false
select new { ParentRoleID = r1.ParentRoleID, RoleID = r1.RoleID, RoleName = r1.RoleName, RoleDesc = r1.RoleDesc, ParentRoleName = r2.RoleName };
}
方法二:普通绑定方法中设置联合主键(用户组别编号和用户编号组合而成)
Casagroup.Entities.EntitiesDataContext eDataContext = new Casagroup.Entities.EntitiesDataContext();
Common _common = new Common();
private void BindUserInfo()
{
UserGroup c = new UserGroup();
//联合查询用户信息
var result = from ugu in eDataContext.UserGroupUser
join us in eDataContext.User on ugu.UserID equals us.UserID
join ug in eDataContext.UserGroup on ugu.UserGroupID equals ug.UserGroupID
select new { ID = ugu.ID + "_" + us.UserID, UserPWD = us.UserPWD, UserGroupID = ugu.UserGroupID, UserID = us.UserID, UserName = us.UserName, UserGroupName = ug.UserGroupName, IsEnabled = us.IsEnabled };
this.gvUser.DataSource = result;
this.gvUser.DataBind();
}