zoukankan      html  css  js  c++  java
  • EF数据Linq方式查询

                using (var ctx = new NorthwindEntities())
                {
                    //单表查询SQL查询方式
                    //SELECT * FROM Customers AS c WHERE c.City = 'London' AND c.CustomerID = 'EASTC'
                    dataGridView1.DataSource = (from c in ctx.Customers where c.City == "London" && c.CustomerID == "EASTC" select c).ToList();
    
                    //模糊查询
                    //SELECT * FROM Customers AS c WHERE c.City LIKE 'L%'
                    dataGridView1.DataSource = (from c in ctx.Customers where c.City.StartsWith("L") select c).ToList();
                    //SELECT * FROM Customers AS c WHERE c.City LIKE '%L'
                    dataGridView1.DataSource = (from c in ctx.Customers where c.City.EndsWith("L") select c).ToList();
                    //SELECT * FROM Customers AS c WHERE c.City LIKE '%L%'
                    dataGridView1.DataSource = (from c in ctx.Customers where c.City.Contains("L") select c).ToList();
                    //SELECT * FROM Customers AS c WHERE c.City='London' ORDER BY c.CustomerID
    
                    //排序
                    //SELECT * FROM Customers AS c WHERE c.City='London' ORDER BY c.CustomerID
                    dataGridView1.DataSource = (from c in ctx.Customers where c.City == "London" orderby c.CustomerID select c).ToList();
    
                    //只查询部分列,并排序
                    //SELECT c.CustomerID, c.CompanyName, c.ContactName FROM Customers AS c
                    //WHERE c.CompanyName = 'The Big Cheese'
                    //ORDER BY c.CompanyName
                    dataGridView1.DataSource = (from c in ctx.Customers where c.CompanyName == "The Big Cheese" orderby c.CompanyName select new { c.CustomerID, c.CompanyName, c.ContactName }).ToList();
    
                    //分组
                    //SELECT c.City,COUNT(c.CompanyName) FROM Customers AS c GROUP BY c.City
                    dataGridView1.DataSource = (from c in ctx.Customers group c by c.City into r orderby r.Count() descending select new { City = r.Key, Count = r.Count() }).ToList();
                }
            }

    数据模型

    界面

  • 相关阅读:
    前端开发 Vue -3axios
    前端开发 Vue -2npm
    前端开发 Vue -1windows环境搭建Vue Node开发环境
    前端开发 Vue -0前言
    linux
    java 框架-缓冲-Redis 2Jedis操作
    java 框架-缓冲-Redis 1概述
    微软银光 silverlight简介
    bs模型与cs模型
    安装vs2010
  • 原文地址:https://www.cnblogs.com/liessay/p/11911059.html
Copyright © 2011-2022 走看看