Git Product home page Git Product logo

banana's Introduction

Developer: Lio.Huang

Package NuGet Stable NuGet Pre-release Downloads
Banana.Uow Banana.Uow Banana.Uow Banana.Uow
Banana.Utility Banana.Utility Banana.Utility Banana.Utility

Banana.Uow

项目介绍

👉English documentation

基于Dapper封装的仓储、工作单元,支持SQL Server, MySQL, Sqlite,Postgresql,Oracle...

一、使用说明

1. 注册链接

 ConnectionBuilder.ConfigRegist("strConn", Banana.Uow.Models.DBType.SqlServer);

2. 模型

引入命名空间:

using Banana.Uow.Models;

创建模型:

   [Table("T_Student")]
   public class Student : IEntity
   {
      // if Oracle db
     //[Key("user_sequence")]
       [Key]
       public int Id { get; set; }
       public string Name { get; set; }
       public int Sex { get; set; }
       public int ClassId { get; set; }
       [Computed]
       public DateTime Createtime { get; set; }
       [Column("UserNameFiel")]
       public string UserName { get; set; }
   }

特性说明:

  • Table:指定实体对应地数据库表名,如果类名和数据库表名不同,需要设置
  • Key:指定此列为自动增长主键(oracle设置序列名称即可)
  • ExplicitKey:指定此列为非自动增长主键(例如guid,字符串列)
  • Computed:计算属性,此列不作为更新
  • Write:指定列是否可写
  • Column:指定列名
  • ExceptUpdate: 指定该列不需要Update操作

3. 仓储使用

3.1 增删改查

    var repo = new Repository<Student>();
    //查询单个
    var model = repo.Query(7);

    //查询列表
    var list = repo.QueryList("Name like @Name", new { Name = "%EminemJK%" });

    //分页查询
    var page1 = repo.QueryList(1,5);
    var page2 = repo.QueryList(2,5);
    … …
    var page0 = repo.QueryList(1, 10, "ID>@Id", new { Id = 2 }, "id", false);

    //删除
    boo b = repo.Delete(model);
    boo b = repo.Delete(new Category(){ Id =7 });

    //更新
    bool model = repo.Update(model);

    //插入
    int id = (int)repo.Insert(new Student() { Name = "EminemJK",… … });

    //批量插入
    bool b = repo.InsertBatch(sql,List);

    //执行语句
    int res = repo.Execute(sql,param);

3.2 多数据库时

    var dbA = "dbStoreA";
    var dbB = "dbStoreA";
    ConnectionBuilder.ConfigRegist("strConnA", DBType.SqlServer2012, dbA);
    ConnectionBuilder.ConfigRegist("strConnB", DBType.SqlServer2012, dbB);
    
    var userInfo_ReadRepo = new Repository<Student>(dbA); 
    var userInfo_WirteRepo = new Repository<Student>(dbA);
    Your code ……

4. 工作单元

using (UnitOfWork uow = new UnitOfWork())
{
       var studentRepo = uow.GetRepository<Student>();
       var model = new Student("EminemJK");
       var sid = studentRepo.Insert(model);

       var classRepo = uow.GetRepository<MClass>();
       var cid = classRepo.Insert(new MClass("Fifth Grade"));
       if (sid > 0 && cid > 0)
       {
            uow.Commit();
       }
       else
       {
            uow.Rollback();
       }
}

多数据库时

using (UnitOfWork uow = new UnitOfWork(IDbConnection context))
{
      Your code
}

OR

using (UnitOfWork uow = new UnitOfWork("dbKey"))
{
      Your code
}

Banana.Utility

公用库 Utility

Name Use
RedisUtils 基于StackExchange.Redis封装
PinYin 拼音帮助类
JavaDate 时间戳
ModelConvertUtil 模型拷贝
PagingUtil 分页
HttpHelper easy Get & Post
EnumDescription 枚举特性说明
Encryption 常用加密解密,DES/MD5/RSA

To Be Continued

👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍


License

MIT

banana's People

Contributors

eminemjk avatar tigeryzx avatar isdaniel avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.