Let me change the question like this:
Which one of the below modes would increase the performance of an application?
- A method in C# which performs about 6 JOIN statements and returns a value.
- An stored procedure which performs 6 JOIN statements
Which of the above would be more efficient in terms of application performance?
Here is the Code:
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;
}
}
Thank you