Skip to content

Repository files navigation

NETCore.DapperKit

Easy use Dapper like ef with DapperKit.


Install with nuget

  • To install NETCore.DapperKit, run the following command in the Package Manager Console
Install-Package NETCore.DapperKit -Version 2.0.0

Add Dapperkit service in starup.cs

  • Using DapperKit extensions
usingNETCore.DapperKit.Extensions;
  • Add Dapperkit service
publicvoidConfigureServices(IServiceCollectionservices){// Add framework services.services.AddMvc();// Add DapperKitservices.AddDapperKit(optionsBuilder =>{optionsBuilder.UseDapper(newDapperKitOptions(){ConnectionString="Data Source=.;User ID=sa;Password='123456';Initial Catalog=DapperDb;MultipleActiveResultSets=True;"});});}

User DapperKit in asp.net core mvc controller

  • Init DapperContext
publicclassAccountController:Controller{privatereadonlyIDapperContext_DapperContext;publicAccountController(IDapperContextcontext){_DapperContext=context;}
...}
  • Use Dapper Like EF
publicasyncTask<IActionResult>Login(LoginViewModelmodel,stringreturnUrl=null){
...var users =await_DapperContext.DbSet<SysUser>().Select<SysUserRole>((u,r)=>newSysUser(){Id=u.Id,IsAdmin=u.IsAdmin,LoginName=u.LoginName,LoginPwd=u.LoginPwd,CreateTime=u.CreateTime,UserName=u.UserName,UserRoleNo=u.UserRoleNo,RoleName=r.Name}).Join<SysUserRole>((u,r)=>u.UserRoleNo==r.No).Where(m =>m.LoginName==model.Account&&m.LoginPwd==model.Password).ToListAsync<SysUser>();
...}

LICENSE

MIT LICESE

About

Dapper extensions

Topics

Resources

Stars

9 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages