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之动态条件查询
  • 相关阅读:
    某个账号微信的微信朋友圈内容抓取 部分好友内容抓取
    密钥登录
    CPU处理器架构和工作原理浅析
    perl 安装Net::ZooKeeper
    perl 安装Net::ZooKeeper
    thinkphp 常用的查询
    thinkphp 常用的查询
    ThinkPHP 3.1.2 模板中的基本语法<2>
    ThinkPHP 3.1.2 模板中的基本语法<2>
    perl post 带上请求头
  • 原文地址:https://www.cnblogs.com/2013likong/p/3484011.html
Copyright © 2011-2022 走看看