洞察如何利用智慧屏第三方App安装提升跨平台小程序的用户体验和安全性
682
2022-10-19
easy4net- 轻量级的ORM框架
easy4net是一个轻量级orm框架,灵活在于可以自己编写复杂的SQL语句查询,简单在于几分钟内便能上手使用,并支持mysql, mssql,oracle, access数据库.
详细文档地址:http://git.oschina-/wangwei123/easy4net/wikis/easy4net
代码生成器:http://oschina-/p/entitycodebuilder
分页查询:
1. 命名参数, ParamMap传参方式:2. 支持多层嵌套查询自动分页功能。
int pageIndex = 1; int pageSize = 3; string sql = "SELECT * FROM (select * from student where age < @age or address= @address) as v"; ParamMap param = ParamMap.newMap(); param.setParameter("age",24); param.setParameter("address", "上海市"); param.setPageIndex(pageIndex); param.setPageSize(pageSize); List
分页查询:
int pageIndex = 1; int pageSize = 3; string sql = "SELECT * FROM student WHERE age < 28"; List
更多查询方式:
**//查询所有 List list = DB.FindAll(); //通过ID主键查询 Student student = DB.FindById
**
新增:
1. 新增后返回新增记录的主键id值2. 主键id值已经自动填充到新增的对象entity中
DBHelper db = DBHelper.getInstance(); Student entity = new Student(); entity.Name = "Lily"; entity.Gender = "女"; entity.Age = 23; entity.Address = "上海市徐汇区中山南二路918弄"; int id = db.Save(entity);
**
修改:
**Student entity = new Student(); entity.UserID = 1; entity.Name = "Andy"; entity.Age = 22; db.Update(entity);**
删除:1. 按对象方式删除数据2. 按主键id方式删除数据
Student student = m_stuList[i]; //remove a object db.Remove(student); //remove by id db.Remove(student.UserID);
数据库与C#对象映射关系配置:
**[Serializable] [Table(Name = "U_Student")] public class Student { //主键自增长 [Id(Name = "UserID", Strategy = GenerationType.INDENTITY)] public int UserID { get; set; } //数据库字段U_Name [Column(Name = "U_Name")] public string Name { get; set; } [Column(Name = "U_Age")] // int? 允许int类型为空 public int? Age { get; set; } [Column(Name = "U_Gender")] public string Gender { get; set; } [Column(Name = "U_Address")] public string Address { get; set; } [Column(Name = "U_CreateTime")] public DateTime? CreateTime { get; set; } [Column(Name = "ClassID")] public int? ClassID { get; set; } // 不保存该属性值到数据库库,忽略新增和修改 [Column(Name = "ClassName",IsInsert=false,IsUpdate=false)] public string ClassName { get; set; } // 不保存该属性值到数据库库,忽略新增和修改 [Column(Name = "Teacher", IsInsert = false, IsUpdate = false)] public string Teacher { get; set; } } }**
数据库连接配置 web.config中:
dbType中配置sqlserver, mysql, oracle来支持不同的数据库
**< configuration>
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~