189 8069 5689

LinqtoSQL基础篇-创新互联

成都创新互联从2013年开始,是专业互联网技术服务公司,拥有项目网站设计制作、成都做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元铜官做网站,已为上家服务,为铜官各地企业和个人服务,联系电话:028-86922220>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> end =
                Expression.Lambda>(condition, new ParameterExpression[] { c });

var query = Linq.K_SysModuleNode.Where(end);
Linq之动态条件查询
名称栏目:LinqtoSQL基础篇-创新互联
网页链接:http://jkwzsj.com/article/hsecc.html

其他资讯