zoukankan      html  css  js  c++  java
  • LInQ的一些查询

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    using LinQ.Models;
    
    namespace LinQ
    {
        class Program
        {
            static void Main(string[] args)
            {
                //1.查询东京的学生
                
                List<Student> StuList = Student.GetStudentList();
                //stu 数据范围?,StuList数据源
                //select * from tableName
                var stuQuery = from stu in StuList
                               where stu.studentCity == "东京"
                               select stu;
                foreach (var item in StuList)
                {
                    Console.WriteLine("姓名{0},城市{1},性别{2}",item.studentName,item.studentCity,item.studentSex);
                }
    
    
                Console.WriteLine("---------查询单个属性---姓名--------------------");
    
                //查询单个属性
                var stuQueryName = from stu in StuList
                                   where stu.studentCity == "东京"
                                   select stu.studentName;
    
                foreach (var item in stuQueryName)
                {
                    Console.WriteLine("姓名{0}", item);
                }
    
                Console.WriteLine("---------查询多个属性--------");
                //查询多个属性
                var temp = from stu in StuList
                           where stu.studentCity == "东京"
                           select new {id=stu.studentID,name=stu.studentName,stu.studentCity };
    
                foreach (var item in temp)
                {
                    Console.WriteLine("id:{0},姓名{1},城市{2}",item.id,item.name,item.studentCity);
                }
    
                //连接查询
                Console.WriteLine("-------连接查询-------");
                DemoJoinOn();
    
                Console.ReadKey();
            }
            public static void DemoJoinOn()
            {
                
                var temp = from stu in Student.GetStudentList()
                           join teach in Teacher.GetTeacherList()
                           on stu.teacherID equals teach.teacherID
                           select new { stu.studentName, teach.teacherName };
    
                foreach (var item in temp)
                {
                    Console.WriteLine("学生姓名:{0},老师姓名{1}",item.studentName,item.teacherName);
                }
            }
        }
    }
  • 相关阅读:
    存储过程分页
    SQL內置Function游标函数
    SQL 2000中的触发器使用
    使用.NET自带的功能制作简单的注册码
    在ASP.NET里轻松实现缩略图
    推荐几个用得上且免费的 .NET控件
    SQL內置Function日期和时间函数
    常用的asp代碼和javascript代碼
    SQL內置Function元数据函数
    數據庫中代@@的參數說明
  • 原文地址:https://www.cnblogs.com/yaodengfeng/p/7760778.html
Copyright © 2011-2022 走看看