LiXiang98

导航

 

2023年10月26日

摘要: 一、与数据库表映射 1、安装依赖:Install-Package Microsoft.EntityFrameworkCore.SqlServer; 2、创建实体类: public record Person { public long? Id { get;set; } public string N 阅读全文
posted @ 2023-10-26 21:24 LiXiang98 阅读(93) 评论(0) 推荐(0)
 

2023年10月25日

摘要: 原因:在构建充血模型时,为构建合法的对象,对象赋值都在私有的。属性少的时候可以直接写构造函数,属性多时就不太合适了。 如何解决这个问题呢?代码如下 Book类: 1 public class Book 2 { 3 public long Id { get; private set; } 4 publ 阅读全文
posted @ 2023-10-25 09:34 LiXiang98 阅读(21) 评论(0) 推荐(0)
 

2023年10月24日

摘要: 一、在.net 中使用日志系统 1 // 可以直接写Loging Provider 2 services.AddLoging(builder=>{ 3 builder.AddConsole();//console log 4 ... 5 }); 二、文本日志 .net 没有提供文本日志,使用第三方的 阅读全文
posted @ 2023-10-24 16:01 LiXiang98 阅读(46) 评论(0) 推荐(0)
 
摘要: 1、在Controller中可以通过HttpContext获取Services,然后获取到注入的服务 var hostEnvironment2 = HttpContext.RequestServices.GetRequiredService<IHostEnvironment>(); 2、利用静态类方 阅读全文
posted @ 2023-10-24 09:46 LiXiang98 阅读(108) 评论(0) 推荐(0)
 

2023年10月16日

摘要: 方式1:使用Newtonsoft.Json // str 为一个json字符串 JObject jobj = JObject.Parse(str); foreach (var prop in jobj.Properties()) { Console.WriteLine($"字段名:{prop.Nam 阅读全文
posted @ 2023-10-16 16:31 LiXiang98 阅读(347) 评论(0) 推荐(0)
 

2022年10月9日

摘要: 比如一个方法里面是一个Task,且没有await,方法运行结束,当前Scope就释放了,此时就需要创建一个独立于当前请求的scope。 在遇到lifetime的一些其他错误的时候也可以试试使用ServiceScopeFactory。 public class Test { private reado 阅读全文
posted @ 2022-10-09 10:06 LiXiang98 阅读(52) 评论(0) 推荐(0)
 
摘要: public Enum TestType { TypeA,TypeB } 1 public Interface ITest 2 { TestType Type { get; } 3 void SayHi(); 4 } 1 public Class TestA:ITest 2 { 3 Public T 阅读全文
posted @ 2022-10-09 09:36 LiXiang98 阅读(22) 评论(0) 推荐(0)
 
摘要: 在csproj中添加 <ItemGroup> <FrameworkReference Include="Microsoft.AspNetCore.App" /> </ItemGroup> 阅读全文
posted @ 2022-10-09 09:10 LiXiang98 阅读(174) 评论(0) 推荐(0)
 

2022年10月8日

摘要: 问题:枚举类通过EFCore映射到数据库默认是int类型,无法在数据库中清晰的知道存储的数据是什么,需要查询文档或者查看代码。 结论:在实体类对应的的Config中增加 builder.Property(e=>e.Money.MoneyType).HasConversion<string>(); 如 阅读全文
posted @ 2022-10-08 16:45 LiXiang98 阅读(97) 评论(0) 推荐(0)
 

2022年5月9日

摘要: 1、 2、 3、点击确定; 4、关闭; 5、添加配置转换 6、切换为刚加的“ddd”即可。 阅读全文
posted @ 2022-05-09 20:04 LiXiang98 阅读(22) 评论(0) 推荐(0)