Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ADO.net-复杂数据绑定_C#_.net_Database_Vb.net_Ado.net - Fatal编程技术网

C# ADO.net-复杂数据绑定

C# ADO.net-复杂数据绑定,c#,.net,database,vb.net,ado.net,C#,.net,Database,Vb.net,Ado.net,我正在处理一个我自己无法解决的问题。我还试图在网上找到解决办法,但没有成功 这里是细节 这是关于一个复杂的数据绑定(在本例中是3个数据库表) 这里是我的表(抽象),试图对用户/组关联进行建模 Table 1 - tblUsers ------------------------------ field1: Id field2: Username field3: Password Table 2 - tblGroups ------------------------------ field1:

我正在处理一个我自己无法解决的问题。我还试图在网上找到解决办法,但没有成功

这里是细节

这是关于一个复杂的数据绑定(在本例中是3个数据库表)

这里是我的表(抽象),试图对用户/组关联进行建模

Table 1 - tblUsers
------------------------------
field1: Id
field2: Username
field3: Password

Table 2 - tblGroups
------------------------------
field1: Id
field2: GroupName
field3: Description

Table 3 - tblUsers_Groups
------------------------------
field1: Id
field2: Id_tblUsers
field3: Id_tblGroups
这样,单个用户可以属于多个组(反之亦然)

我一直在尝试创建一个WinForm,比如主-细节类,主网格应该在tblUsers中显示用户,并且。。。根据我在那里选择的内容,在详细信息网格中显示所选用户所属的组。。。但是使用tblGroups中的信息


有人能帮我解决这个问题吗?

第一个表3不应该有和ID
使用Id\u tblUsers、Id\u tblGroups的组合键

在.NET中,我是这样做的

    public class UserGroup : Object
    {   // NO editing just add remove
        public User User { get; private set; }
        public Group Group { get; private set; }
        public override bool Equals(Object obj)
        {
            //Check for null and compare run-time types.
            if (obj == null || !(obj is UserGroup)) return false;
            UserGroup item = (UserGroup)obj;
            return (User.ID == item.User.ID && Group.ID == item.Group.ID);
        }
        public override int GetHashCode() { return (User.ID & 0xffff) + (Group.ID << 16); }
        public UserGroup(User user, Group group)
        { User = user; Group = group; }
    }
公共类用户组:对象
{//无需编辑,只需添加或删除
公共用户用户{get;private set;}
公共组组{get;private set;}
公共覆盖布尔等于(对象对象对象)
{
//检查null并比较运行时类型。
如果(obj==null | |!(obj是用户组))返回false;
用户组项=(用户组)对象;
返回(User.ID==item.User.ID&&Group.ID==item.Group.ID);
}
public override int GetHashCode(){return(User.ID&0xffff)+(Group.ID x.User==this)
.选择(x=>x.Group)
.OrderBy(y=>y.Name)
.ToList();}
然后将组中的妹妹返回用户

这可能看起来很复杂,但真正酷的是一个单一的主人。所以,当您修改UserGroup的HashSet时,它会反映在User和Group中

public List<Group> Groups
{   get { return usersGroups.Where(x => x.User == this)
                            .Select(x => x.Group)
                            .OrderBy(y => y.Name)
                            .ToList(); } }