<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          easy4net輕量級的ORM框架

          聯(lián)合創(chuàng)作 · 2023-09-30 02:39

          easy4net是一個輕量級orm框架,靈活在于可以自己編寫復雜的SQL語句查詢,簡單在于幾分鐘內(nèi)便能上手使用,并支持mysql, mssql, oracle, access數(shù)據(jù)庫.

          詳細文檔地址:http://git.oschina.net/wangwei123/easy4net/wikis/easy4net

          代碼生成器:http://www.oschina.net/p/entitycodebuilder

          分頁查詢:

          1. 命名參數(shù), 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<Student> student = DB.FindBySql<Student>(sql, param); 

          分頁查詢:

          int pageIndex = 1; 
          int pageSize = 3; 
          string sql = "SELECT * FROM student WHERE age < 28"; 
          List<Student> list1 = DB.FindBySql<Student>(sql , pageIndex, pageSize);

          更多查詢方式:

          //查詢所有 
          List list = DB.FindAll(); 
          //通過ID主鍵查詢 
          Student student = DB.FindById<Student>(5); 
          //通過SQL語句查詢 
          List<Student> list1 = DB.FindBySql<Student>("SELECT * FROM U_Student WHERE U_Age < 28"); 
          //查詢某個字段 
          List<Student> list2 = DB.FindByProperty<Student>("U_Name", "Lily Mary"); 
          // 通過自定義條件查詢
          // SELECT xxx FROM U_Student WHERE U_Name LIKE '%Lily%' OR U_Age < 28 DbCondition cond1 = new DbCondition().Where().Like("U_Name", "Lily").OrLessThan( "U_Age", 28); 
          List<Student> list3 = DB.Find<Student>(cond1); 
          // 多表關(guān)聯(lián)查詢 
          DbCondition cond2 = new DbCondition("SELECT s.*,c.teacher,c.className FROM U_Student s " "INNER JOIN U_Class c ON s.classID = c.ID").Where().RightLike("U_Name","Lil"); List<Student> list4 = DB.Find<Student>(cond2); 
          //通過條件查詢數(shù)量
          //SELECT count(0) FROM U_Student WHERE U_Name = 'Lily Mary' AND U_Age = 28 
          DbCondition cond3 = new DbCondition().Where("U_Name", "Andy").And("U_Age", 28); int count = DB.FindCount<Student>(cond3); 

          新增:

          1. 新增后返回新增記錄的主鍵id值
          2. 主鍵id值已經(jīng)自動填充到新增的對象entity中

          DBHelper db = DBHelper.getInstance(); 
          Student entity = new Student(); 
          entity.Name = "Lily"; 
          entity.Gender = "女"; 
          entity.Age = 23; 
          entity.Address = "上海市徐匯區(qū)中山南二路918弄"; 
          int id = db.Save(entity); 


          修改:

          Student entity = new Student(); 
          entity.UserID = 1; 
          entity.Name = "Andy"; 
          entity.Age = 22; db.Update(entity); 

          刪除:
          1. 按對象方式刪除數(shù)據(jù)
          2. 按主鍵id方式刪除數(shù)據(jù)

          Student student = m_stuList[i]; 
          //remove a object 
          db.Remove(student); 
          //remove by id 
          db.Remove(student.UserID);



          數(shù)據(jù)庫與C#對象映射關(guān)系配置:


          [Serializable] 
          [Table(Name = "U_Student")] 
          public class Student { 
              //主鍵自增長  
              [Id(Name = "UserID", Strategy = GenerationType.INDENTITY)] 
              public int UserID { get; set; } 
          
              //數(shù)據(jù)庫字段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; } 
          
              // 不保存該屬性值到數(shù)據(jù)庫庫,忽略新增和修改  
              [Column(Name = "ClassName",IsInsert=false,IsUpdate=false)] 
              public string ClassName { get; set; } 
          
              // 不保存該屬性值到數(shù)據(jù)庫庫,忽略新增和修改  
              [Column(Name = "Teacher", IsInsert = false, IsUpdate = false)]                        public string Teacher { get; set; } 
          } 
          }

          **數(shù)據(jù)庫連接配置 web.config中: **

          dbType中配置sqlserver, mysql, oracle來支持不同的數(shù)據(jù)庫

          <configuration> 
              <appSettings> 
                  <add key="DbType" value="sqlserver"/> 
                  <add key="connectionString" value="Data Source=127.0.0.1;Initial Catalog=test;User ID=test;Password=test123;Trusted_Connection=no;Min Pool Size=10;Max Pool Size=100;"/> 
              <!--<add key="DbType" value="mysql"/>
                  <add key="connectionString" value="Data Source=127.0.0.1;port=8001;User ID=test;Password=123456;DataBase=test;Min Pool Size=10;Max Pool Size=100;"/>--> 
              </appSettings> 
          </configuration> 


          瀏覽 21
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  久久午夜无码鲁丝片精品 | 国产传媒久久久久 | 美女黄页网站 | 高清无码视频在线播放 | 日韩高清无码本道 |