• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






java小兵

 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理

02 2022 档案

 
asp.net core signalR (1)
摘要:服务端SignalR支持 // 加入signalR,需要cors支持 builder.Services.AddSignalR(); string[] urls = { "http://localhost:3000" }; builder.Services.AddCors(options => { o 阅读全文
posted @ 2022-02-26 20:44 .net一小兵
asp.net core 数据校验
摘要:使用asp.net core默认的属性 public class LoginRequest { [MinLength(3)] public string Username { get; set; } [Required] public string Email { get; set; } [MinL 阅读全文
posted @ 2022-02-22 20:20 .net一小兵
asp.net core host service
摘要:host service public class DemoService01 { public int Add(int a, int b) { return a + b; } } // 由于Host service是单例的,所以无法使用IOC注入非单例服务 // 需要使用IServiceScope 阅读全文
posted @ 2022-02-22 18:48 .net一小兵
asp.net core swagger传bearer token
摘要:在program.cs中注入swagger的Authorize支持 builder.Services.AddSwaggerGen(options => { OpenApiSecurityScheme scheme = new OpenApiSecurityScheme() { Description 阅读全文
posted @ 2022-02-21 20:20 .net一小兵
asp.net core 使用JWT实现认证
摘要:用到的package <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.2" /> 定义jwt options public class JWTOptions { public 阅读全文
posted @ 2022-02-21 19:49 .net一小兵
asp.net core 使用Identity Framework实现账户管理
摘要:用到的package <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.2" /> <PackageReference Include="Microsoft.Entit 阅读全文
posted @ 2022-02-17 21:21 .net一小兵
asp.net core middleware
摘要:测试用中间件 // 需要安装Dynamic.Json // install-package Dynamic.Json public class CheckMiddleware { private RequestDelegate Next { get; init; } public CheckMidd 阅读全文
posted @ 2022-02-15 14:51 .net一小兵
asp.net core 限流filter
摘要:限流过滤器 public class RateLimitActionFilter : IAsyncActionFilter { private IMemoryCache MemoryCache { get; init; } public RateLimitActionFilter(IMemoryCa 阅读全文
posted @ 2022-02-13 19:25 .net一小兵
asp.net core transaction support filter
摘要:TransactionScopeFilter [AttributeUsage(AttributeTargets.Method)] public class TransactionalSupportAttribute : Attribute { } public class TransactionSc 阅读全文
posted @ 2022-02-13 19:01 .net一小兵
asp.net core exception filter
摘要:exception filter public class MyExceptionFilter : IAsyncExceptionFilter { private IWebHostEnvironment WebHostEnvironment { get; set; } public MyExcept 阅读全文
posted @ 2022-02-12 20:01 .net一小兵
asp.net core IDistributedCache
摘要:使用redis包 install-package Microsoft.Extensions.Caching.Redis 配置redis-server builder.Services.AddDistributedRedisCache(options => { options.InstanceName 阅读全文
posted @ 2022-02-11 20:24 .net一小兵
asp.net core 缓存使用
摘要:// 在program.cs中加入这句,加入缓存支持 builder.Services.AddMemoryCache(); public class Book { public int Id { get; init; } public string Title { get; init; } publ 阅读全文
posted @ 2022-02-09 18:50 .net一小兵
asp.net core 参数使用
摘要:[ApiController] [Route("[controller]")] public class PersonController : ControllerBase { [HttpGet("add")] // 如果使用[controller]/[action],则url变成Person/Ad 阅读全文
posted @ 2022-02-06 12:43 .net一小兵
dotnet record
摘要:本质上record是一个实现了Equals()/GetHashCode()和ToString()的class record Person(int Id, string Name, int Age) // 这3个都是只读属性 { public string NickName { get; set; } 阅读全文
posted @ 2022-02-05 09:07 .net一小兵
dotnetcore EF 动态查询指定列
摘要:普通情况下,可以通过select实现查询指定列, ctx.Students.Select(s => new {s.Id, s.Name}); ctx.Students.Select(s => new object[] {s.Id, s.Name}); 这里使用动态方式实现select查询指定列 us 阅读全文
posted @ 2022-02-04 19:01 .net一小兵
dotnetcore EF 表达式
摘要:使用Expression using (MyDbContext ctx = new MyDbContext()) { Expression<Func<Student, bool>> exp01 = s => s.Name.Contains("stu"); foreach (Student s in 阅读全文
posted @ 2022-02-04 18:09 .net一小兵
dotnetcore EF 乐观锁并发控制
摘要:使用IsConcurrencyToken()设置并发token builder.Property(h => h.Owner).IsConcurrencyToken(); 使用SQL语句类似以下 update house set owner = @p0 where id = 1 and owner = 阅读全文
posted @ 2022-02-03 19:22 .net一小兵
dotnetcore EF 查询筛选
摘要:增加IsDeleted属性 软删除,设置IsDelete为true Student s = ctx.Students.FirstOrDefault(s => s.Id == 10); s.IsDeleted = true; await ctx.SaveChangesAsync(); 调用HasQue 阅读全文
posted @ 2022-02-03 18:22 .net一小兵
dotnetcore EF 小技巧(但不推荐)
摘要:正常情况下,都是通过EF先取出entity,再修改或删除。 这样会生成一条select和一条update或delete语句,但是通过update/delete sql可以一句就完成。 使用以下代码,通过欺骗EF的方式,使得一句sql完成目标。 using (MyDbContext ctx = new 阅读全文
posted @ 2022-02-02 20:07 .net一小兵
dotnetcore EF 获取Entity状态
摘要:通过EntityEntry可以获取Entity状态 using Microsoft.EntityFrameworkCore.ChangeTracking; static async Task Main(string[] args) { using (MyDbContext ctx = new MyD 阅读全文
posted @ 2022-02-02 19:20 .net一小兵
dotnetcore EF 非原生sql调用
摘要:尽量使用EF的异步调用 await ctx.Students.ToListAsync() await foreach (var s in ctx.Students.AsAsyncEnumerable()) FormattableString使用 int a = 111; string world = 阅读全文
posted @ 2022-02-01 19:38 .net一小兵