public PageArray <Install> SearchInstallDB(InstallPara model) { using (var db = new EFDbContext()) { var args = new SqlParameter[] { new SqlParameter { ParameterName = "ID", Value = model.ID }, new SqlParameter { ParameterName = "City", Value = model.City }, new SqlParameter { ParameterName = "Type", Value = model.Type }, }; SQLPara(args);//处理空值 db.Database.CreateIfNotExists(); var list = db.Database.SqlQuery <Install>( "Select * from Install where (@ID is null or ID=@ID) and (@City is null or City=@City) and (@Type is null or Type=@Type)", args ).ToArray(); return(new PageArray <Install>(1, list, 0, model.rows, list.Length)); } //DbContext } //SearchInstallDB
}//InsertInstallDB //接收输入数据 //按照输入的参数执行插入sql语句,保存更改 //不返回数据 public PageArray <Install> DeleteInstallDB(InstallPara model) { using (var db = new EFDbContext()) { var args = new SqlParameter[] { new SqlParameter { ParameterName = "ID", Value = model.ID }, new SqlParameter { ParameterName = "City", Value = model.City }, new SqlParameter { ParameterName = "Type", Value = model.Type }, }; SQLPara(args);//处理空值 db.Database.CreateIfNotExists(); db.Database.ExecuteSqlCommand( "delete from Install where (@ID is null or ID=@ID) and (@City is null or City=@City) and (@Type is null or Type=@Type) ", args ); db.SaveChanges(); } return(null); }//DeleteInstallDB
} //SearchInstallDB //接收输入数据 //按照输入的参数执行插入sql语句,保存更改 //不返回数据 public PageArray <Install> InsertInstallDB(InstallPara model) { using (var db = new EFDbContext()) { var args = new SqlParameter[] { new SqlParameter { ParameterName = "ID", Value = model.ID }, new SqlParameter { ParameterName = "City", Value = model.City }, new SqlParameter { ParameterName = "Type", Value = model.Type }, }; SQLPara(args);//处理空值 db.Database.CreateIfNotExists(); db.Database.ExecuteSqlCommand( "insert into Install values(@ID,@City,@Type) ", args ); for (int i = 0; i < 1000; i++) { args = new SqlParameter[] { new SqlParameter { ParameterName = "ID", Value = i }, new SqlParameter { ParameterName = "City", Value = RandomString() }, new SqlParameter { ParameterName = "Type", Value = "a" }, }; db.Database.ExecuteSqlCommand( "insert into Install values(@ID,@City,@Type) ", args ); } //db.Install.Add(new Install(model.ID,model.City,model.Type)); db.SaveChanges(); } return(null); }//InsertInstallDB
}//SearchInstallDB //接受输入数据 //不返回结果 public ActionResult DeleteInstallDB(InstallPara model) { var result = aSvr.DeleteInstallDB(model); return(null); }//SearchInstallDB
//public ActionResult SearchData() //{ // Install i1 = new Install(); // Install i2 = new Install(); // i1.ID=1; // i1.City="anhui"; // i1.Type="a"; // i2.ID=2; // i2.City="shanghai"; // i2.Type="b"; // Install[] list = {i1,i2}; // // return Json(i1, JsonRequestBehavior.AllowGet); // return Json(new { // total=2, // rows=list // }); //}//SearchData //接受输入数据 //返回数据库查询结果 public ActionResult SearchInstallDB(InstallPara model) { var result = aSvr.SearchInstallDB(model); return(Json(new { rows = result.Array, total = result.Total })); }//SearchInstallDB