zoukankan      html  css  js  c++  java
  • List.Jion

    private void simpleButton1_Click(object sender, EventArgs e)
            {
                IList<Channel> list = new List<Channel>();
                Channel item = new Channel();
                item.ID = 1;
                item.ChannelName = "1";
                list.Add(item);
    
                item = new Channel();
                item.ID = 2;
                item.ChannelName = "2";
                list.Add(item);
    
                IList<Channel1> list1 = new List<Channel1>();
                Channel1 item1 = new Channel1();
                item1.ID = 1;
                item1.ChannelName1 = "11";
                list1.Add(item1);
    
                item1 = new Channel1();
                item1.ID = 22;
                item1.ChannelName1 = "22";
                list1.Add(item1);
    
                var result = from left1 in list
                             join right1 in list1 on left1.ID equals right1.ID into temp
                             select new
                             {
                                 ID = left1.ID,
                                 ChannelName = left1.ChannelName,
                                 ChannelName1 = temp.Select(t => t.ChannelName1).FirstOrDefault()
                             };
    
                var result1 = list.Join(list1, T1 => T1.ID, T2 => T2.ID, (T1, T2) => new {
                    Name = T1.ChannelName,
                    ID = T1.ID,
                    NickName = T2.ChannelName1
                });
    
                this.gridControl1.DataSource = result1;
            }
        }
        public class Channel
        {
            private int _ID = 0;
            private string _ChannelName = "";
            /// <summary>
            /// 
            /// </summary>
            public int ID
            {
                set { this._ID = value; }
                get { return this._ID; }
            }
            /// <summary>
            /// 
            /// </summary>
            public string ChannelName
            {
                set { this._ChannelName = value; }
                get { return this._ChannelName; }
            }
            public Channel() { }
            public Channel(int _ID, string _ChannelName)
            {
                this.ID = _ID;
                this.ChannelName = _ChannelName;
            }
        }
    
        public class Channel1
        {
            private int _ID = 0;
            private string _ChannelName1 = "";
            /// <summary>
            /// 
            /// </summary>
            public int ID
            {
                set { this._ID = value; }
                get { return this._ID; }
            }
            /// <summary>
            /// 
            /// </summary>
            public string ChannelName1
            {
                set { this._ChannelName1 = value; }
                get { return this._ChannelName1; }
            }
            public Channel1() { }
            public Channel1(int _ID, string _ChannelName1)
            {
                this.ID = _ID;
                this.ChannelName1 = _ChannelName1;
            }
        }
    
  • 相关阅读:
    Validation failed for one or more entities
    sql 存储过程
    SQL Server分页3种方案比拼
    case when 用法
    C#如何计算代码执行时间
    透过 Jet.OLEDB 读取 Excel里面的数据
    DataBinding?资料系结?资料绑定?
    ASP.NET的OutputCache
    我想写程序#3 之 「简单地设计自己的数据表(Table)」
    我想写程序#1 之 「先确立志向」
  • 原文地址:https://www.cnblogs.com/liushunli/p/7171640.html
Copyright © 2011-2022 走看看