1

質問を次のように変更させてください。

アプリケーションのパフォーマンスを向上させるモードは次のうちどれですか?

  1. 約 6 つの JOIN ステートメントを実行し、値を返す C# のメソッド。
  2. 6 つの JOIN ステートメントを実行するストアド プロシージャ

アプリケーションのパフォーマンスに関して、上記のうちどれがより効率的ですか?

コードは次のとおりです。

public bool UserHasAccess(string userName, string actionName)
    {
        var decodedUserName = UtilityHands.GeneralTools.DecodeString(userName);
        using (MAHAL_E_MA_Repository.UnitOfWork unit = new UnitOfWork())
        {
            var theUserID = unit.UserRepository.Get(filter: s => s.UserName.Equals(decodedUserName)).First().ID;
            var userInRoleGroup = unit.RoleGroupUserRepository.Get(filter: r => r.UserInRole == theUserID).ToList();

            var roleInRoleGroups = unit.RoleOfRoleGroupRepository.Get().ToList();
            var serviceOfRoles = unit.ServiceOfRoleRepository.Get().ToList();
            var serviceOfAction = unit.ServiceOfActionRepository.Get().ToList();
            var roles = unit.RoleRepository.Get().ToList();
            var service = unit.ServiceRepository.Get().ToList();
            var actions = unit.ActionProviderRepository.Get().ToList();

            var rolesOfRoleGroupJoin = userInRoleGroup.Join(roleInRoleGroups,
                                            (u => u.RoleGroupID),
                                            (r => r.RoleGroupID),
                                            ((u, r) => new { userInRoleGroup = u, roleInRoleGroups = r }));

            var rrgOfRolesJoin = rolesOfRoleGroupJoin.Join(roles,
                                                      (r => r.roleInRoleGroups.RoleID),
                                                      (rs => rs.RoleID),
                                                      ((r, rs) => new { rolesOfRoleGroupJoin = r, roles = rs }));

            var roleServiceJoin = rrgOfRolesJoin.Join(serviceOfRoles,
                                                    (rrg => rrg.roles.RoleID),
                                                    (sor => sor.RoleID),
                                                    ((rrg, sor) => new { rrgOfRolesJoin = rrg, serviceOfRoles = sor }));

            var serviceOfRolesServiceJoin = roleServiceJoin.Join(service,
                                                                (rs => rs.serviceOfRoles.ServiceID),
                                                                (s => s.ServiceID),
                                                                ((rs, s) => new { roleServiceJoin = rs, service = s }));

            var serviceActionJoin = serviceOfRolesServiceJoin.Join(serviceOfAction,
                                                                  (sors => sors.service.ServiceID),
                                                                  (soa => soa.ServiceID),
                                                                  ((sors, soa) => new { serviceOfRolesServiceJoin = sors, serviceOfAction = soa }));

            var serviceActionWithActionJoin = serviceActionJoin.Join(actions,
                                                                    (sa => sa.serviceOfAction.ActionProviderID),
                                                                    (a => a.ActionProviderID),
                                                                    ((sa, a) => new { serviceActionJoin = sa, actions = a }));

            var actionNames = serviceActionWithActionJoin.Where(s => s.actions.Description.Equals(actionName));

            if (actionNames != null && actionNames.Count() > 0)
            {
                return true;
            }
            return false;
        }
    }

ありがとうございました

4

1 に答える 1