添加导航属性
This commit is contained in:
Binary file not shown.
@@ -87,5 +87,17 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.IncludeTest">
|
||||
<summary>
|
||||
极爽导航属性
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.ContextTest">
|
||||
<summary>
|
||||
自由导航属性
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -15,12 +15,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class BaseCrudController<T> : ControllerBase where T : BaseModelEntity,new()
|
||||
{
|
||||
public readonly ILogger<T> _logger;
|
||||
public IBaseService<T> _baseService;
|
||||
public IRepository<T> _repository;
|
||||
private readonly ILogger<T> _logger;
|
||||
private IBaseService<T> _baseService;
|
||||
private IRepository<T> _repository;
|
||||
public BaseCrudController(ILogger<T> logger, IBaseService<T> iBaseService)
|
||||
{
|
||||
_logger = logger;
|
||||
|
||||
@@ -23,11 +23,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
private IStringLocalizer<LocalLanguage> _local;
|
||||
private IUserService _iUserService;
|
||||
private IRoleService _iRoleService;
|
||||
//你可以依赖注入服务层各各接口,也可以注入其他仓储层,怎么爽怎么来!
|
||||
public TestController(ILogger<UserEntity> logger, IUserService iUserService, IStringLocalizer<LocalLanguage> local)
|
||||
public TestController(ILogger<UserEntity> logger, IRoleService iRoleService, IUserService iUserService, IStringLocalizer<LocalLanguage> local)
|
||||
{
|
||||
_local = local;
|
||||
_iUserService = iUserService;
|
||||
_iRoleService = iRoleService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -42,19 +44,19 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
//非常好,使用UserService的特有方法
|
||||
await _iUserService.DbTest();
|
||||
|
||||
//非常好,依赖注入使用其他Service的特有方法(就tm一张表,现在自己注入自己)
|
||||
await _iUserService.DbTest();
|
||||
//非常好,依赖注入使用其他Service的特有方法
|
||||
await _iRoleService.DbTest();
|
||||
|
||||
//很核理,使用仓储的通用方法
|
||||
await _iUserService._repository.GetListAsync();
|
||||
|
||||
//挺不错,依赖注入其他仓储(就tm一张表,现在自己注入自己)
|
||||
await _iUserService._repository.GetListAsync();
|
||||
//挺不错,依赖注入其他仓储
|
||||
await _iRoleService._repository.GetListAsync();
|
||||
|
||||
//不建议操作,直接切换其他仓储(就tm一张表,现在自己切换自己)
|
||||
await _iUserService._repository.ChangeRepository<Repository<UserEntity>>().GetListAsync();
|
||||
//不建议操作,直接切换其他仓储
|
||||
await _iUserService._repository.ChangeRepository<Repository<RoleEntity>>().GetListAsync();
|
||||
|
||||
//恭喜你已经毕业了!此后将有一天,接手到这个的软件的程序员将破口大骂。
|
||||
//直接操作Db对象???恭喜你已经毕业了!此后将有一天,接手到这个的软件的程序员将破口大骂。
|
||||
await _iUserService._repository._Db.Queryable<UserEntity>().ToListAsync();
|
||||
|
||||
return Result.Success().SetData(await _iUserService.DbTest());
|
||||
@@ -132,6 +134,15 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
|
||||
}
|
||||
|
||||
//emmmm,看来一张表已经满足不了,接下来将要大更新一波
|
||||
/// <summary>
|
||||
/// 极爽导航属性
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
//Sqlsugar精髓之一!必学!最新版本
|
||||
public async Task<Result> IncludeTest()
|
||||
{
|
||||
return Result.Success().SetData(await _iUserService.GetListInRole());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
16
Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs
Normal file
16
Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface IRoleService
|
||||
{
|
||||
/// <summary>
|
||||
/// DbTest
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<List<RoleEntity>> DbTest();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface IRoleService:IBaseService<RoleEntity>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface IUserRoleService:IBaseService<UserRoleEntity>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -30,5 +30,12 @@ namespace Yi.Framework.Interface
|
||||
/// <param name="userAction"></param>
|
||||
/// <returns></returns>
|
||||
public Task<bool> Register(UserEntity userEntity, Action<UserEntity> userAction = null);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 导航属性关联角色
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<List<UserEntity>> GetListInRole();
|
||||
}
|
||||
}
|
||||
|
||||
24
Yi.Framework.Net6/Yi.Framework.Model/Models/RoleEntity.cs
Normal file
24
Yi.Framework.Net6/Yi.Framework.Model/Models/RoleEntity.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarTable("Role")]
|
||||
public partial class RoleEntity:BaseModelEntity
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="RoleName" )]
|
||||
public string RoleName { get; set; }
|
||||
/// <summary>
|
||||
/// 租户Id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="TenantId" )]
|
||||
public long? TenantId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarTable("UserRole")]
|
||||
public partial class UserRoleEntity:BaseModelEntity
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="RoleId" )]
|
||||
public long? RoleId { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="UserId" )]
|
||||
public long? UserId { get; set; }
|
||||
/// <summary>
|
||||
/// 租户Id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="TenantId" )]
|
||||
public long? TenantId { get; set; }
|
||||
}
|
||||
}
|
||||
15
Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs
Normal file
15
Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public partial class UserEntity:BaseModelEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 看好啦!ORM精髓,导航属性
|
||||
///</summary>
|
||||
[Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.UserId), nameof(UserRoleEntity.RoleId))]
|
||||
public List<RoleEntity> Roles { get; set; }
|
||||
}
|
||||
}
|
||||
17
Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs
Normal file
17
Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class RoleService
|
||||
{
|
||||
public async Task<List<RoleEntity>> DbTest()
|
||||
{
|
||||
return await _repository._Db.Queryable<RoleEntity>().ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class RoleService : BaseService<RoleEntity>, IRoleService
|
||||
{
|
||||
public RoleService(IRepository<RoleEntity> repository) : base(repository)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class UserRoleService : BaseService<UserRoleEntity>, IUserRoleService
|
||||
{
|
||||
public UserRoleService(IRepository<UserRoleEntity> repository) : base(repository)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,5 +65,11 @@ namespace Yi.Framework.Service
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<List<UserEntity>> GetListInRole()
|
||||
{
|
||||
return await _repository._Db.Queryable<UserEntity>().Includes(u => u.Roles).ToListAsync();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user