zoukankan      html  css  js  c++  java
  • ASP.NET

    以后SqlSugar所有更新都会在这个贴子更新

    SqlSugar是一款轻量级的MSSQL ORM ,除了具有媲美ADO的性能外还具有和EF相似简单易用的语法。

    学习列表

      0、功能更新

     1、SqlSugar基础应用

     2、使用SqlSugar处理大数据

     3、使用SqlSugar实现Join  待更新

     4、使用SqlSugar实现分页+分组+多列排序 待更新

     5、节点故障如何进行主从调换

     

    版本2.1/2016-1-7:

    多表查询 添加 自动生成  实体类  的字符串函数(虽然有生带的实体生成类,这儿提供一个更方便的解决方案)

    1、将原本的SelectToList<V_Student>写成 ToClass,因为我们还没有V_Student这个类

    2、复制list中的字符串,建创到V_Student里面

    3、将ToClass改成SelectToList完成

    自动获取页面参数:

    在特定的情况下可以减少控制器和服务层之间的参数传递

    红色部分省略掉了,减少参数赋值 如图:

     db.Queryable<Student>().Where("id=@id",new {id=Request["id"]}).ToList()

    看一看GetParameterDictionary的好处吧,有多少条件写多少Where

     

    现在Foreach搞定

    多库架构添加多字段排序

    2016/2/14

    版本2.1.0.1

    使用queryable 查询时,可以类名与表名不一样

    2016/2/14

    版本2.1.0.2

     

     

    2016/2/14

    版本2.1.0.3

    添加功能:可以生成视图类

    2016/2/14

    版本2.1.0.6

    支持无参数更新:   db.Update(new School { id = id, name = "蓝翔2" });

    MAPPING 表名支持  添、删和改 

    2016/5/12

    版本 2.2

    修复个别BUG

    添加权限全局过滤器功能

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using SqlSugar;
    using WebTest.Dao;
    using Models;
    
    namespace WebTest.NewDemo
    {
        public partial class Filter : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                using (SqlSugarClient db = SugarDaoFilter.GetInstance())//开启数据库连接
                {
                    //queryable
                    db.CurrentFilterKey = "role";
                    var list = db.Queryable<Student>().ToList(); //通过全局过滤器对需要权限验证的数代码进行过滤
                    //相当于db.Queryable<Student>().Where("id=@id",new{id=1})
    
    
    
                    //sqlable
                    var list2 = db.Sqlable().Form<Student>("s").SelectToList<Student>("*");
                    //相当于同上
                }
    
            }
        }
        /// <summary>
        /// 扩展SqlSugarClient
        /// </summary>
        public class SugarDaoFilter
        {
            //禁止实例化
            private SugarDaoFilter()
            {
    
            }
            /// <summary>
            /// 页面所需要的过滤函数
            /// </summary>
            private static Dictionary<string, KeyValueObj> _filterParas = new Dictionary<string, KeyValueObj>()
            {
              { "role",new KeyValueObj(){ Key=" id=@id" , Value=new{ id=1}}},
              { "org",new KeyValueObj(){ Key=" orgId=@orgId" , Value=new{ orgId=1}}},
            };
            public static SqlSugarClient GetInstance()
            {
                string connection = System.Configuration.ConfigurationManager.ConnectionStrings[@"sqlConn"].ToString(); //这里可以动态根据cookies或session实现多库切换
                var reval = new SqlSugarClient(connection);
                reval.SetFilterFilterParas(_filterParas);
                return reval;
            }
        }
    }

     2016/6/23

     版本2.3.2.0.

    多表查询 支持反回动态方法和JSON

    更新指添加了 可以指定不更新的列

    更新添加了 非主键自添列自动过滤功能

    支持返回  <string[]>

    支持返回  <int> <string> 以外的更多值类型

    支持反回 字典类型

  • 相关阅读:
    使用CustomValidate自定义验证控件
    C#中金额的大小写转换
    Andriod出错之Unable to build: the file dx.jar was not loaded from the SDK folder!
    VC 编写的打字练习
    机房工作笔记Ping只有单向通
    web服务协同学习笔记(1)
    Dll 学习3 将MDI子窗口封装在DLL中
    机房工作学习文件共享
    Andriod出错之Failed to find an AVD compatible with target 'Android 2.2'
    Andriod出错之wrapper was not properly loaded first
  • 原文地址:https://www.cnblogs.com/sunkaixuan/p/5109688.html
Copyright © 2011-2022 走看看