linq to sql

1.模糊查询:

   

                ZNDataClassesDataContext znDB = new ZNDataClassesDataContext();

                var query = (from v in znDB.表名(视图名) select v).Where(c => c.a.Contains(参数1)).Where(c => c.b.Contains(参数2)).Where(c => c.date1>= Convert.ToDateTime(参数3.Trim() == "" ? "1900-01-01" : 参数3.Trim()) && c.date1<= Convert.ToDateTime(参数4.Trim() == "" ? "5012-08-21" : 参数4.Trim())).Where(c => (参数5== "0") ? 1 == 1 : c.ID== Convert.ToInt32(参数5(下拉框Value)));               

               return query;

2.更新(传参方式)

          

                 ZNDataClassesDataContext znDB = new ZNDataClassesDataContext();                

       实体对象 nSingle = (from enList in znDB.表名  where enList.ID == 参数ID    select enList).Single<实体对象>();

                 enSingle.字段名= 参数;

                 znDB.SubmitChanges();                

       return true;

posted @ 2012-08-24 15:39  猎鹰-aspnet  阅读(3677)  评论(0编辑  收藏  举报