/// <summary> /// 用户接口 /// </summary> public interface IUserService { string GetName(); /// <summary> /// 查询用户信息 /// </summary> /// <param></param> /// <returns></returns> Task<User> GetDetailsAsync(string account); } /// <summary> /// 用户实现 /// </summary> public class UserService : IUserService { private readonly OpenDbContext _dbContext; public UserService(OpenDbContext dbContext) { _dbContext = dbContext; } public string GetName() { return "AZRNG"; } ///<inheritdoc cref="IUserService.GetDetailsAsync(string)"/> public async Task<User> GetDetailsAsync(string account) { return await _dbContext.Set<User>().FirstOrDefaultAsync(t => t.Account == account).ConfigureAwait(false); } }
一般更推荐建立指定的返回Model类,然后只查询需要的内容,不直接返回实体类
控制器方法
/// <summary> /// 查询用户详情 /// </summary> /// <param></param> /// <returns></returns> [HttpGet] public async Task<ActionResult<User>> GetDetailsAsync(string account) { return await _userService.GetDetailsAsync(account).ConfigureAwait(false); }
查询结果
{ "id": "e8976d0a-6ee9-4e2e-b8d8-1fe6e85b727b", "account": "azrng", "password": "123456", "money": 0, "deleted": false, "creater": "azrng", "createTime": "2021-05-09T15:48:45.730302", "modifyer": "azrng", "modifyTime": "2021-05-09T15:48:45.730425" }
参考文档实体类型:
实体属性:
到此这篇关于.NET之生成数据库全流程实现的文章就介绍到这了,更多相关.NET 生成数据库内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章: