我有三个数据库实体表角色、特征、角色特征
`Public class Roles
{
public long RoleIdPk { get; set; }
public string RoleName { get; set; }
public string RoleDescription{ get; set; }
public int CreatedBy{ get; set; }
}
Public class Features
{
public long FeatureIDPk{ get; set; }
public string FeatureName{ get; set; }
public string FeatureDescription{ get; set; }
public int CreatedBy{ get; set; }
}
Public class RoleFeatures
{
public long RoleIDFk{ get; set; }
public long FeatureIDFk{ get; set; }
public string ViewPermission{ get; set; }
public string addPermission{ get; set; }
public stringEditPermission{ get; set; }
public string DeletePermission{ get; set; }
}`
我想得到一个输出,就像在所有GetAllRoles API中我想要的输出
`"status": "true",
"data": {
“roles”:[
{ "roleId": "number",
"roleName": "string",
"features":[
{
“featureId”:”number”,
“featureName”:”string”,
"view": "string",
"add": "string",
"edit": "string",
"delete": "string"
},
{
“featureId”:”number”,
“featureName”:”string”,
"view": "string",
"add": "string",
"edit": "string",
"delete": "string"
},
]
}
}`
public class GetRolesResponse : FeaturesDTO
{
public long RoleId { get; set; }
public string RoleName { get; set; }
public List<FeaturesDTO> Features { get; set; }
}
public class FeaturesDTO
{
public long FeatureId { get; set; }
public string FeatureName { get; set; }
public bool ViewPerm { get; set; }
public bool AddPerm { get; set; }
public bool EditPerm { get; set; }
public bool DeletePerm { get; set; }
}
}
角色MapCreateMap<Roles, GetRolesResponse>();
列出roles 1 = _mapper.Map<List>(roles);
GeallRoles查询List<Role>roles = await _context.Roles.ToListAsync();
但是在getall方法的角色中我没有得到特征表的数组。我只得到RoleDTO与值。该怎么办呢?
1条答案
按热度按时间nwnhqdif1#
您的
Roles
型号没有与GetRolesResponse
中的Features
匹配的相应List
,因此Features
将为null。你能改变
RoleFeatures
和FeaturesDTO
的模型结构,使两者匹配吗?如果你可以的话,它将非常简单。下面是一个例子:型号:
公司简介:
控制器:
测试结果: