LinqtoSqlDataContext Linq = new LinqtoSqlDataContext(ConfigurationManager.ConnectionStrings["sz_imt20131024pmConnectionString"].ConnectionString);
DataContext对象
var query = from usersTable in Linq.UsersTable
where usersTable.Uid > &&usersTable.Username.StartsWith("张")
orderby usersTable.Uid descending
select new
{
Uid = usersTable.Uid,
Username = usersTable.Username
};
或者 var query= Linq.UsersTable.Where(a => a.Uid > && a.Username.StartsWith("张"));
查询
UsersTable user = new UsersTable
{
Username = "小张",
Sex = "女",
Password = ""
}; Linq.UsersTable.InsertOnSubmit(user);
Linq.SubmitChanges();
添加
UsersTable UT = Linq.UsersTable.Single(a => a.Uid == );
UT.Username = "小明";
Linq.SubmitChanges();
更新
UsersTable UT = Linq.UsersTable.Single(a => a.Uid == );
Linq.UsersTable.DeleteOnSubmit(UT);
Linq.SubmitChanges();
删除
//输出参数
string name=""; Linq:DataContext对象;PROC_SELECTBYUID:存储过程名称
var query = Linq.PROC_SELECTBYUID(ref name);
调用存储过程
//字符串数组
string[] starts = new string[];
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之动态条件查询