//删除 db.Delete<School, int>(10); db.Delete<School>(it => it.id > 100); //主键批量删除 db.Delete<School, , , }); //非主键批量删除 db.Delete<School, string>(it => it.name, new string[] { "" }); db.Delete<School, int>(it => it.id, new int[] { 20, 22 }); //假删除 //db.FalseDelete<school>("is_del", 100); //等同于 update school set is_del=1 where id in(100) //db.FalseDelete<school>("is_del", it=>it.id==100);
6、插入
db.Insert(GetInsertItem()); //插入一条记录 (有主键也好,没主键也好,有自增列也好都可以插进去) db.InsertRange(GetInsertList()); //批量插入 支持(别名表等功能) db.SqlBulkCopy(GetInsertList()); //批量插入 适合海量数据插入,要求实体与数据库一致,不支持(别名表、排除列等功能) //设置不插入列 db.DisableInsertColumns = };//sex列将不会插入值 Student s = new Student() { name = + new Random().Next(1, int.MaxValue), sex = }; var id = db.Insert(s); //插入 sex = db.Queryable<Student>().Single(it => it.id == id.ObjToInt()).sex;name = db.Queryable<Student>().Single(it => it.id == id.ObjToInt()).name;//有值
7、枚举支持
var stuList = db.Queryable<Student>().ToList(); db.Insert<Student>(new Student() { sch_id = SchoolEnum.北大青鸟 }); db.Update<Student>(new Student() { sch_id = SchoolEnum.it清华, id = 11 }); var stuList2 = db.Queryable<Student>().Where(it => it.sch_id == SchoolEnum.全智).ToList();
8、实体生成加T4
//可以结合别名表,请看别名表的用法 //db.SetMappingTables(mappingTableList); db.ClassGenerating.CreateClassFiles(db, (), ); //只生成student和school表的实体 db.ClassGenerating.CreateClassFilesByTableNames(db, , , , }); str = db.ClassGenerating.TableNameToClass(db, ); ); str2 = db.ClassGenerating.SqlToClass(db, , ); tempItem = ClassTemplate.ItemTemplate;temp = ClassTemplate.Template; //设置新格式模板 //主键Guid.New(), //CreateTime为DateTime.Now //IsRemove=0 //UpdateTime为DateTime.Now ClassTemplate.Template = ; str3 = db.ClassGenerating.TableNameToClass(db, );
View Code使用T4
详细教程:
9、ADO.NET
); ); ); ); r4.Dispose(); ); ); p1 = db.GetDataTable(, new {id=1 }); , , } });p3 = db.GetDataTable(, ,1) );
View Code10、日志记录功能