当前位置: 首页> 财经> 创投人物 > 软件开发工程师发展前景_网站建站商城_2022年新闻大事_百度经验发布平台

软件开发工程师发展前景_网站建站商城_2022年新闻大事_百度经验发布平台

时间:2025/8/16 3:28:45来源:https://blog.csdn.net/weixin_72254790/article/details/143970967 浏览次数:0次
软件开发工程师发展前景_网站建站商城_2022年新闻大事_百度经验发布平台

关于Sqlsugar

项目模板:

实体(仅参考 可以不看)

-- inpatient.cs

-- Recorddetail.cs

1. launchSettings.json 数据库配置 

"profiles": {"http": {...默认"environmentVariables": {"ASPNETCORE_ENVIRONMENT": "Development","LOCAL_DB_TYPE": "Oracle","LOCAL_DB_URL": "Data Source=域名/服务名;User ID=用户名;Password=密码"}}},

2.在program 将SqlSugarClient注入

builder.Services.AddKeyedScoped<ISqlSugarClient>("local", (_,_) => new SqlSugarClient(new ConnectionConfig
{DbType = DbType.Oracle,ConnectionString = builder.Configuration.GetSection("LOCAL_DB_URL").Value,IsAutoCloseConnection = true,
}));

AddKeyedScooped 是以键值对的方式注册。

3.在服务中使用SqlSugarClient

通过[FromKeyedServices("local")] 来获取键为”local“的这个SqlSugarClient

// --IServicepublic interface IGetinformation // 定义接口{Task<Recorddetail> Getxaml(Inpatient inpatient);}// --Servicepublic class Getinformation([FromKeyedServices("local")] ISqlSugarClient client) : IGetinformation // 接口实现public async Task<Recorddetail> Getxaml(Inpatient inpatient){// 一个简单的条件查询// $"select noofinpat from Inpatient it where(it.patid == {inpatient.patid})"await client.Queryable<Inpatient>().Where(it => it.patid == inpatient.patid &&it.incount==inpatient.incount).Select(it=>it.noofinpat).FirstAsync();}

在program 再将这条服务注入

builder.Services.AddScoped<IGetinformation, Getinformation>();

4. 通过控制器中暴露请求

[Route("api/[controller]")]
[ApiController]
public class GetinformationController(IGetinformation service) : ControllerBase
{[HttpGet("[action]")]public async Task<EmrXamlResponse> GetXaml([FromBody] Inpatient inpatient){var result = await service.Getxaml(inpatient);return new EmrXamlResponse(){xaml = result.content,Code = result.content==null ? -1 : 1,ErrMsg = result.name};}
}

关键字:软件开发工程师发展前景_网站建站商城_2022年新闻大事_百度经验发布平台

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: