惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CERT Recently Published Vulnerability Notes
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
Security Latest
Security Latest
P
Privacy International News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
S
Secure Thoughts
PCI Perspectives
PCI Perspectives
Simon Willison's Weblog
Simon Willison's Weblog
D
DataBreaches.Net
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
罗磊的独立博客
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
V
V2EX
Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tenable Blog
T
Threat Research - Cisco Blogs
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
Lohrmann on Cybersecurity
F
Full Disclosure
H
Help Net Security
博客园 - Franky
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
Engineering at Meta
Engineering at Meta
A
Arctic Wolf
O
OpenAI News
S
Securelist

博客园 - 赶路人之刚出发

集成WebSecurity的Authorize进行身份验证时,数据库连接报错问题 Html.ActionLink传递参数 Automapper结合EF实现insert,update方法 MVC中使用RemoteAttribute异步远程验证 Html.RenderPartial WebMatrix.WebSecurity创建自定义用户属性 强类型view中List<Model〉问题 ViewBag任意属性的实现方法 params关键字 配置LINQ中的datacontext的log路径,以记录datacontext执行了的查询sql SortedList Linq to objects示例 yield return 和 Func Lamda表达式 IDisposable 匿名类型与扩展方法 对象初始化器和集合初始化器 C#自动属性 .net random伪随机数
LINQ join/left join/cross join/group by/group join/sortedlist/cast
赶路人之刚出发 · 2013-04-27 · via 博客园 - 赶路人之刚出发
    public class Classroom
    {
        /// <summary>
        /// 班级Id
        /// </summary>
        public int ClassId { get; set; }
        /// <summary>
        /// 班级名称
        /// </summary>
        public string ClassName { get; set; }

    }
    public class Student
    {
        /// <summary>
        /// 学生编号
        /// </summary>
        public int StuId { get; set; }
        /// <summary>
        /// 学生姓名
        /// </summary>
        public string StuName { get; set; }

        /// <summary>
        /// 班级ID
        /// </summary>
        public int ClassId { get; set; }

        /// <summary>
        /// 班级
        /// </summary>
        public Classroom Classrooms { get; set; }

    }
    public class Score
    {
        /// <summary>
        /// 分数Id
        /// </summary>
        public int ScoreId { get; set; }
        /// <summary>
        /// 学科名称
        /// </summary>
        public string ItemName { get; set; }
        /// <summary>
        /// 学生ID
        /// </summary>
        public int StuId { get; set; }
        /// <summary>
        /// 学生
        /// </summary>
        public Student Students { get; set; }
        /// <summary>
        /// 分数
        /// </summary>
        public double Scores { get; set; }
    }
   
    public class Program
    {
        
       

        static void Main()
        {
            List<Student> lstStudent = new List<Student>
            {
                new Student{StuId=1,StuName="stu1",ClassId=1},
                new Student{StuId=2,StuName="stu2",ClassId=2},
                new Student{StuId=4,StuName="stu3",ClassId=2}
            };
            List<Classroom> lstClassRoom = new List<Classroom>
            {
                new Classroom{ ClassId=1, ClassName="class1"},
                new Classroom{ ClassId=2, ClassName="class2"},
            };
            List<Score> lstScores = new List<Score>
            {
                new Score{ ItemName="Chinese", ScoreId=1, StuId=1, Scores=90},
                new Score{ ItemName="Chinese2", ScoreId=2, StuId=2,Scores=80},
                new Score{ ItemName="Chinese3", ScoreId=3, StuId=5,Scores=80}
            };
            //内连接
            var query1=lstStudent.Join(lstScores, stu => stu.StuId, score => score.StuId, (stu, score) => new { name = stu.StuName, Item = score.ItemName, scores = score.Scores });
            //内连接2
            query1 = from a in lstStudent
                     join b in lstScores
                     on a.StuId equals b.StuId
                     select new
                     {
                         name = a.StuName,
                         Item = b.ItemName,
                         scores = b.Scores,
                     };
            //左链接
            query1 = from a in lstStudent.AsEnumerable()
                     join b in lstScores
                     on a.StuId equals b.StuId
                     into temp
                     from m in temp.DefaultIfEmpty(new Score{ StuId=a.StuId , ItemName = "没参考", Scores = 0 })
                     select new
                     {
                         name=a.StuName,
                         Item = m.ItemName,
                         scores = m.Scores,
                     };
            //表A.GroupJoin(表B,表A外键,表B外键,处理方法)
            //表A中数据全显示,表B关联上的就显示,否则为空,类似于左查询
            query1 = lstStudent.GroupJoin(lstScores, m => m.StuId, o => o.StuId, (stu, score) => new { name = stu.StuName, Item = score.First().ItemName, scores = score.First().Scores });
            foreach (var item in query1)
            {
            }
            //交叉连接
            query1 = from a in lstStudent
                     from b in lstScores                                          
                     select new
                     {
                         name = a.StuName,
                         Item = b.ItemName,
                         scores = b.Scores,
                     };
            var tmpQuery1=from a in lstStudent
                   join b in lstScores
                   on a.StuId equals b.StuId select new 
                   {
                        classid=a.ClassId,
                         name = a.StuName,
                         Item = b.ItemName,
                         scores = b.Scores,
                   };
            //group by
            var tmpGroupQuery = from a in tmpQuery1
                                group a by a.classid
                                    into sums
                                    select new
                                    {
                                        classid = sums.Key,
                                        score = sums.Sum(o => o.scores)
                                    };
            
            SortedList<int, Student> mySortlist = new SortedList<int, Student>
            {
                {12,new Student{ ClassId=1, StuId=1, StuName="stu1"}},
                {5,new Student{ ClassId=1, StuId=2, StuName="stu2"}},
                {4,new Student{ ClassId=1, StuId=3, StuName="stu3"}}
            };
            //mySortlist.Add(4, new Student { ClassId = 1, StuId = 3, StuName = "stu6" });

            int[] ints = new int[10];
            object obj = ints;
            object[] objarr = obj as object[];

            ArrayList strs = new ArrayList { 1, 2, 3, 4, 5 };
            //ArrayList实现的事IEnumerable而非IEnumerable<T>,要用LINQ查询则必须用Cast方法进行转换
            var str = from m in strs.Cast<int>() select m;
            string stra = "What's your Name";
            var capChars = from m in stra
                           let a=(int)m
                           where a==97
                           select m;