在ASP.NET Core中使用Except方法时显示错误答案

时间:2019-06-02 08:59:01

标签: c# entity-framework entity-framework-core

我想创建一个动态权限。

如果从客户端发送的列表以及数据库中包含的每个动作都被忽略并从列表中删除,则信息将从客户端发送并在操作中进行评估。

客户端发送如下信息:

df = pd.DataFrame(data)

new_data = []
for date in df.date.unique():
  df_temp = df[df.date == date]
  temp_max = list(df_temp.temp_max)
  temp_min = list(df_temp.temp_min)

  new_data.append({'date':date, 'temp_max':temp_max, 'temp_min':temp_min})

以及在ASP.NET Core中:

0:
 Actions: Array(4)
 0: {ActionId: 100663387}
 1: {ActionId: 100663388}
 2: {ActionId: 100663389}
 3: {ActionId: 100663390}
 controllerID: "35ba32ce-f980-3b9d-a38b-3ca854dcb063"
 roleId: 1004
1:
 Actions: Array(2)
 0: {ActionId: 100663395}
 1: {ActionId: 100663395}
 controllerID: "9a722402-cc69-3ad0-a24e-f1f166a46880"
 roleId: 1004

问题是,当我使用该方法时,它不会忽略匹配的数据

[HttpPost("[action]")]
public async void AddClaim(List<RecAccessLevel> model, CancellationToken cancellationToken)
{
        foreach (var item in model)
        {
            var CurrentActions = roleClaimService.TableAsNoTracking
                .Where(x => x.RoleId == item.RoleId && x.ControllerId == item.ControllerID)
                .Select(r => new Action
                {
                    ActionId = r.ActionId
                }).ToList();

            var newActionToAdd = item.Actions.Except(CurrentActions).ToList();

            foreach (var itemAdd in newActionToAdd)
            {
                await roleClaimService.AddAsync(new RoleClaim
                {
                    ActionId = itemAdd.ActionId,
                    ControllerId = item.ControllerID,
                    RoleId = item.RoleId,
                    ClaimType = "DynamicPemission",
                    ClaimValue = string.Format($"{item.RoleId}:{item.ControllerID}:{itemAdd.ActionId}")
                }, cancellationToken);
            }
        }
}

0 个答案:

没有答案