1 public class user
2 {
3 public string uesrID;
4 public string userName;
5 public virtual ICollection<usergroup> Members;
6 }
7
8 public class usergroup
9 {
10 public string usergroupid;
11 public string usergroupname;
12 }
最终希望的结果是:
有两个文本框和一个datagrid,希望这样绑定的:
txt_userid.text = userid;
txt_username.text = username;
datagrid.datasource = user.usergroup.toList();
请教一下查询的C#语句如何写的?好像要做一个扩展是吧,具体的一下子想不起来了,
希望园子里路过的朋友指点下.
修正后的关联关系:userID
1 public class user
2 {
3 public string uesrID;
4 public string userName;
5 public virtual ICollection<usergroup> Members;
6 }
7
8 public class usergroup
9 {
10 public string uesrID;
11 public string usergroupid;
12 public string usergroupname;
13 }
这两个类应该有关联关系的吧
是的,不好意思,关键的地方写漏了,主外键关系是userID
1 public class user
2 {
3 public string uesrID;
4 public string userName;
5 public virtual ICollection<usergroup> Members;
6 }
7
8 public class usergroup
9 {
10 public string uesrID;
11 public string usergroupid;
12 public string usergroupname;
13 }
@denli:
var query=from u in user
from ug in usergroup
where ug.userID==u.userID
select new{userID=u.userID,userName=u.userName,groups=ug};