zoukankan      html  css  js  c++  java
  • Linq to SQL 基础篇

    LinqtoSqlDataContext Linq = new LinqtoSqlDataContext(ConfigurationManager.ConnectionStrings["sz_imt20131024pmConnectionString"].ConnectionString);
    DataContext对象
    var query = from usersTable in Linq.UsersTable
                            where usersTable.Uid > 1&&usersTable.Username.StartsWith("")
                            orderby usersTable.Uid descending
                            select new
                            {
                                Uid = usersTable.Uid,
                                Username = usersTable.Username
                            };
    或者
    
    var query= Linq.UsersTable.Where(a => a.Uid > 1 && a.Username.StartsWith(""));
    查询
    UsersTable user = new UsersTable
                {
                    Username = "小张",
                    Sex = "",
                    Password = "123"
                };
    
                Linq.UsersTable.InsertOnSubmit(user);
                Linq.SubmitChanges();
    添加
    UsersTable UT = Linq.UsersTable.Single(a => a.Uid == 1);
                UT.Username = "小明";
                Linq.SubmitChanges();
    更新
    UsersTable UT = Linq.UsersTable.Single(a => a.Uid == 3);
                Linq.UsersTable.DeleteOnSubmit(UT);
                Linq.SubmitChanges();
    删除
    //输出参数
    string name="";
    
    Linq:DataContext对象;PROC_SELECTBYUID:存储过程名称
    var query = Linq.PROC_SELECTBYUID(ref name);
    调用存储过程
    //字符串数组
    string[] starts = new string[2];
                ParameterExpression c = Expression.Parameter(typeof(K_SysModuleNode), "c");
                Expression condition = Expression.Constant(false);
                foreach (string item in starts)
                {
                    Expression con = Expression.Call(
                        Expression.Property(c, typeof(K_SysModuleNode).GetProperty("NodeName")),
                        typeof(string).GetMethod("StartsWith", new Type[] { typeof(string) }),
                        Expression.Constant(item)
                        );
                    condition = Expression.Or(con,condition);
                }
                Expression<Func<K_SysModuleNode, bool>> end =
                    Expression.Lambda<Func<K_SysModuleNode, bool>>(condition, new ParameterExpression[] { c });
    
                var query = Linq.K_SysModuleNode.Where(end);
    Linq之动态条件查询
  • 相关阅读:
    快速理解平衡二叉树、B-tree、B+tree、B*tree
    centos 7(6) linux系统安装 mysql5.7.17(glibc版)
    关于使用Hibernate+spring+dubbo的实现微服务对象查询
    Keepalived+Nginx实现高可用(HA)
    Nginx源码安装
    Keepalived安装与配置
    单点fastDfs+centos7搭建
    Dubbo+zookeeper使用方法以及注意事项
    mac 下 iterm2 不能使用 rz sz
    java 无符号整型
  • 原文地址:https://www.cnblogs.com/2013likong/p/3484011.html
Copyright © 2011-2022 走看看